private void btnSumit_Click(object sender, EventArgs e)
        {

            SqlConnection thisConn 
= new SqlConnection
(
"data source=LOCALHOST\\SQLEXPRESS;Integrated Security=true;database=DormManage");
            SqlCommand thisCommand 
= new SqlCommand();
            
            
try
            {
                thisConn.Open();
                lblErrorShow.Text 
= "数据库连接中";

                thisCommand.Connection 
= thisConn;
                thisCommand.CommandText 
= "insert into T_MainTable(F_Name,F_Province)values('" + tbName.Text + "','" + tbProvince.Text + "');";
                thisCommand.ExecuteNonQuery();
            }
            
catch (Exception ex)
            {
                lblErrorShow.Text 
= ex.Message;
            }
            
finally
            {
                thisConn.Close();
            }

 

今天首次用VS08 连 SQL SERVER 05  遇到了很多问题

 

1.流水号可以用identity 插入的时候省略这项

2.然后注意连 EXPRESS时候的字符串

3.注意 SQL语言中 字符串是用''括起来的 不能忘

4.conn和command 的实例化在try块的外面 这样finally的时候可以dispose 掉

posted on 2008-08-01 00:11  LMT  阅读(128)  评论(0编辑  收藏  举报