C# 关于datagridview 绑定列名
我查询的时候绑定了用户和密码2段怎么一查询就又弹出数据库的列名代码:privatevoidbutton1_Click(objectsender,EventArgse){S...
我查询的时候绑定了 用户和密码2段 怎么一查询就又弹出数据库的列名
代码:
private void button1_Click(object sender, EventArgs e)
{
String username = this.username.Text.Trim();
SqlConnection conn = new SqlConnection("Data Source=ADMINISTRATOR_U\\SQLEXPRESS;Initial Catalog=text;User ID=sa;password=123456;");
string sql = string.Format("select username,userpwd from [user] where 1=1 ");
if (username != "")
{
sql = sql + "and username =" + "'" + username + "'";
}
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "[user]");
dataGridViewDACX.DataSource = ds.Tables[0];
dataGridViewDACX.Columns[0].DataPropertyName = "username";
dataGridViewDACX.Columns[1].DataPropertyName = "userpwd";
}
搜索
复制 展开
代码:
private void button1_Click(object sender, EventArgs e)
{
String username = this.username.Text.Trim();
SqlConnection conn = new SqlConnection("Data Source=ADMINISTRATOR_U\\SQLEXPRESS;Initial Catalog=text;User ID=sa;password=123456;");
string sql = string.Format("select username,userpwd from [user] where 1=1 ");
if (username != "")
{
sql = sql + "and username =" + "'" + username + "'";
}
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "[user]");
dataGridViewDACX.DataSource = ds.Tables[0];
dataGridViewDACX.Columns[0].DataPropertyName = "username";
dataGridViewDACX.Columns[1].DataPropertyName = "userpwd";
}
搜索
复制 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询