问一个简单的程序
用c#做个窗体
一个文本框,一个按钮,一个dategride
数据库中表table有个字段title
我在文本框中输入字符,点击按钮,下面那个dategride中就列出table中的所有字段
select * from table where title like '%文本框%'该怎么写啊?
小弟初学.net啊!还什么都不懂啊!
各位高手帮帮忙,指教一下啊!
谢了啊!
用c#做个窗体
一个文本框,一个按钮,一个dategride
数据库中表table有个字段title
我在文本框中输入字符,点击按钮,下面那个dategride中就列出table中的所有字段
select * from table where title like '%文本框%'该怎么写啊?
小弟初学.net啊!还什么都不懂啊!
各位高手帮帮忙,指教一下啊!
谢了啊!
SqlCommand cmd = new SqlCommand("select * from table where title like '%+txt.text+"%'",连接)
sqldatareader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
然后datetrid榜定dr就可以了
sqldatareader dr=cmd.ExecuteReader(CommandBehavior.CloseConnection);
datagrid.datasource=dr;
using System.Data.SqlClient;//输入字符串后,点击按钮下的代码,模仿一下:
SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
try
{
SqlCommand cmd = new SqlCommand("select * from studentInfor where sno like '%"+this.textBox1 .Text +"%'", con);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "student");
this.dataGridView1.DataSource = ds.Tables["student"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message );
}
datagrid.Bind();
using System.Data.SqlClient;//输入字符串后,点击按钮下的代码,模仿一下:
//说明一下:以下student是数据库名,uid用户名,pwd为密码
SqlConnection con = new SqlConnection("server=.;database=student;uid=sa;pwd=0421");
try
{
//studentInfor是表名,sno是列名
SqlCommand cmd = new SqlCommand("select * from studentInfor where sno like '%"+this.textBox1 .Text +"%'", con);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
sda.Fill(ds, "student");
//vs2005下dataGridView,vs2003下用dataGrid
this.dataGridView1.DataSource = ds.Tables["student"];
}
catch (Exception ex)
{
MessageBox.Show(ex.Message );
}