c# asp.net 关于查询数据并显示到文本框控件中具体操作

2024-11-15 19:31:23
推荐回答(3个)
回答1:

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句你得改成适合你自己的!

回答2:

太基础的东西还是去看书吧

回答3:

txtbox.text文本框 数据库dt.rows[索引值][索引值].tostring();
txtbox.text=dt.rows[索引值][索引值].tostring();
Over