Question

i made this coding actually find in stuckoverflow :) and i re made it according to my application and changed connection string and tabe name as well as raw name, it is all correct, no more errors before compiling when i have entered have value to text box i am getting an error at "con.open();" after the connection string plz help me my error message is "Instance failure." my coding is `

 private void textBox_ItemId_TextChanged(object sender, EventArgs e)
    {
        AutoCompleteStringCollection namesCollection = new AutoCompleteStringCollection();
        SqlConnection connection = new SqlConnection(@"Data Source=SAROTH-PC\\SQLEXPRESS;Initial Catalog=noorsons;Integrated Security=True");
        connection.Open();
        SqlCommand cmnd = connection.CreateCommand();
        cmnd.CommandType = CommandType.Text;
        cmnd.CommandText = "SELECT itemcode FROM Invoice_New_Details";
        SqlDataReader dReader;
        dReader = cmnd.ExecuteReader();

        if (dReader.Read())
        {
            while (dReader.Read())
                namesCollection.Add(dReader["english"].ToString());
        }
        else
        {
            MessageBox.Show("Data not found");
        }
        dReader.Close();

        textBox_ItemId.AutoCompleteMode = AutoCompleteMode.Suggest;
        textBox_ItemId.AutoCompleteSource = AutoCompleteSource.CustomSource;
        textBox_ItemId.AutoCompleteCustomSource = namesCollection;
        }`
Was it helpful?

Solution

Since you have marked your connection string with '@', you don't need to have a double slash for Data Source.

Data Source=SAROTH-PC\SQLEXPRESS
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top