目的:想在查询服务窗体,输入书名或编号时,在DataGridView显示符合条件的数据。调试到第三句代码时,却出现始料未及的问题,求解!!!求帮忙!!!初学实在有太多问题了。代码如下:
string yanzheng = this.textBox1.Text.Trim();
int id = Int32.Parse(this.textBox2.Text.Trim());
SqlConnection cnn = new SqlConnection("Data Source=DJK-PC;Initial Catalog=图书管理系统;Integrated Security=True");
cnn.Open();
SqlCommand cd = new SqlCommand();
cmd.CommandText = "select * from 图书状态表 where book_name ='" + yanzheng + "'or book_id ='" + id + "' ";
cmd.Connection = conn;
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds, "图书状态表");
dataGridView1.DataSource = ds.Tables["图书状态表"];
conn.Close();
string yanzheng = this.textBox1.Text.Trim();
int id = Int32.Parse(this.textBox2.Text.Trim());
SqlConnection cnn = new SqlConnection("Data Source=DJK-PC;Initial Catalog=图书管理系统;Integrated Security=True");
cnn.Open();
SqlCommand cd = new SqlCommand();
cmd.CommandText = "select * from 图书状态表 where book_name ='" + yanzheng + "'or book_id ='" + id + "' ";
cmd.Connection = conn;
SqlDataAdapter ada = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
ada.Fill(ds, "图书状态表");
dataGridView1.DataSource = ds.Tables["图书状态表"];
conn.Close();
SqlConnection mycon = new SqlConnection(conn);
mycon.Open();
string selery="SQL语句";
SqlDataAdapter SQLDA = new SqlDataAdapter(selery, conn);
DataSet DS = new DataSet();
SQLDA.Fill(DS);
this.datagridview1.DataSource = DS.Tables[0].DefaultView;
string connectionstring=@"Data Source=.\SQLEXPERSS;AttachDbFilename=|DataDirectory|DatabaseName;"+"Integrated Security=true; Connect Timeout=60; User Instance=True";DatabaseName为数据库名称。
SqlConnection cnn = new SqlConnection(connectionstring);
string connectionstring = "server=localhost; database=DatabaseName;uid=sa;pwd=";
SqlConnection cnn = new SqlConnection(connectionstring);
cnn.Open();
含有转义字符。改成SqlConnection cnn = new SqlConnection(@"Data Source=DJK-PC;Initial Catalog=图书管理系统;Integrated Security=True");
cnn.Open();
疑难解决提示:确保方法参数格式正确。
将一个字符串转换成DataTime时,先分析该字符串以获取日期,然后将每个变量放置到DataTime对象中。