关于C#从数据库取值赋值给变量的问题
本人新学C#,先开始做一个界面试试,但是想从数据库里取一个值与当前值对比,应该怎么取值比较好。
我的代码如下,需要做怎样的修改呢,求各位大大解答
String str = "Data Source=.;Initial Catalog=test;User ID=zwc;Password=hbhhzhen;connect Timeout=30";
SqlConnection conn = new SqlConnection(str);
if (ConnectionState.Closed == conn.State)
{
conn.Open();
}
SqlDataAdapter d = new SqlDataAdapter();
string str1 = "select ID from wupin";
SqlDataAdapter chaxun=new SqlDataAdapter(str1,str);
DataSet rongqi=new DataSet();
chaxun.Fill(rongqi);
int i = int.Parse(rongqi.Tables[0].Rows[0].ToString());
int j=int.Parse(ID.Text);
if (i == j)
{
d.InsertCommand = new SqlCommand("INSERT INTO [In](Inpeople,Intime,Yongtu,ID,Name)Values('" + Pname.Text + "',+'" + DateTime.Now + "','" + Yongtu.Text + "','" + ID.Text + "','" + Wname.Text + "')", conn);
d.InsertCommand.ExecuteNonQuery();
conn.Close();
ID.Clear(); ;
Pname.Clear(); ;
Wname.Clear();
Yongtu.Clear();
MessageBox.Show("添加成功");