Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言从数据库中提取标签文本#_C# - Fatal编程技术网

C# 用C语言从数据库中提取标签文本#

C# 用C语言从数据库中提取标签文本#,c#,C#,我正在C#开发一个小项目。。。使用VisiualStudio 2010。。。我想从数据库中获取标签文本,以便通过按钮更改用户界面语言。。。 我写了这段代码,但是SQLDATAREADER中有一个问题 在它显示的标签文本部分中 System.Data.SqlClient.SqlDataReader 我修不好,你能帮我吗?你可以用 如果要使用ExecuteReader,必须首先存储读取器,然后调用Read并使用reader.GetString(0)获取其值 如果有100个标签会发生什么?打开和关闭连

我正在C#开发一个小项目。。。使用VisiualStudio 2010。。。我想从数据库中获取标签文本,以便通过按钮更改用户界面语言。。。 我写了这段代码,但是SQLDATAREADER中有一个问题

在它显示的标签文本部分中 System.Data.SqlClient.SqlDataReader

我修不好,你能帮我吗?

你可以用


如果要使用ExecuteReader,必须首先存储读取器,然后调用Read并使用reader.GetString(0)获取其值

如果有100个标签会发生什么?打开和关闭连接100次?是的,你是对的,这不是最佳解决方案。。。有没有办法用一个连接进行一些查询?打开一个连接,然后全部读取
 private void button5_Click(object sender, EventArgs e)
        {
            SqlConnection conn = new SqlConnection("Data Source=MAZI-PC\\PROJECTACC;Initial Catalog=programDB;Integrated Security=True");
            SqlCommand cmd = new SqlCommand("select label_sh from label_text where label_form='2' and label_form_labelID='1'", conn);
            conn.Open();
            label1.Text = cmd.ExecuteReader().ToString();
            conn.Close();

            SqlConnection conn1 = new SqlConnection("Data Source=MAZI-PC\\PROJECTACC;Initial Catalog=programDB;Integrated Security=True");
            SqlCommand cmd1 = new SqlCommand("select label_sh from label_text where label_form='2' and label_form_labelID='2'", conn1);
            conn1.Open();
            label2.Text = cmd1.ExecuteReader().ToString();
            conn1.Close();

            SqlConnection conn2 = new SqlConnection("Data Source=MAZI-PC\\PROJECTACC;Initial Catalog=programDB;Integrated Security=True");
            SqlCommand cmd2 = new SqlCommand("select label_sh from label_text where label_form='2' and label_form_labelID='3'", conn2);
            conn2.Open();
            label3.Text = cmd2.ExecuteReader().ToString();
            conn2.Close();
        }
label3.Text = (string) cmd2.ExecuteScalar();