现在的位置: 首页 > 综合 > 正文

今天的无聊

2012年03月13日 ⁄ 综合 ⁄ 共 963字 ⁄ 字号 评论关闭

        
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 掉

抱歉!评论已关闭.