0

我做了这个编码实际上是在stuckoverflow中找到的:)我根据我的应用程序重新制作并更改了连接字符串和标签名称以及原始名称,这一切都是正确的,在我输入时编译之前没有更多错误对文本有价值我在“con.open();”处遇到错误 在连接字符串请帮助我之后,我的错误消息是“实例失败”。我的编码是`

 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;
        }`
4

1 回答 1

3

由于您已将连接字符串标记为“@”,因此数据源不需要使用双斜杠。

Data Source=SAROTH-PC\SQLEXPRESS
于 2013-11-12T20:21:05.413 回答