c# asp.net 关于查询数据并显示到文本框控件中具体操作
3个回答
展开全部
conn = new SqlConnection(connString);
SqlCommand sc = new SqlCommand();
sc.Connection = conn;
sc.CommandText = "select count(*) from FilesInfo ";
conn.Open();
int count = (int)sc.ExecuteScalar();
conn.Close();
sc.CommandText = "select * from FilesInfo where filesName=@filesName";
SqlParameter sp1 = sc.Parameters.Add("@filesName", SqlDbType.VarChar);
sp1.Value = treeView1.SelectedNode.Text;
conn.Open();
SqlDataReader reader = sc.ExecuteReader();
for (int j = count - 1; j >= 0; j--)
{
if (reader.Read())
{
FilesText = reader["filesTxt"].ToString();
FilesID = reader["filesID"].ToString();
textBox1.Text = FilesText;
textBox4.Text = FilesID;
}
}
conn.Close();
上面这段代码就是你想要的!SQL句你得改成适合你自己的!
SqlCommand sc = new SqlCommand();
sc.Connection = conn;
sc.CommandText = "select count(*) from FilesInfo ";
conn.Open();
int count = (int)sc.ExecuteScalar();
conn.Close();
sc.CommandText = "select * from FilesInfo where filesName=@filesName";
SqlParameter sp1 = sc.Parameters.Add("@filesName", SqlDbType.VarChar);
sp1.Value = treeView1.SelectedNode.Text;
conn.Open();
SqlDataReader reader = sc.ExecuteReader();
for (int j = count - 1; j >= 0; j--)
{
if (reader.Read())
{
FilesText = reader["filesTxt"].ToString();
FilesID = reader["filesID"].ToString();
textBox1.Text = FilesText;
textBox4.Text = FilesID;
}
}
conn.Close();
上面这段代码就是你想要的!SQL句你得改成适合你自己的!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询