用c#和是sql05做web系统,如姓名、性别、身份证号、出生日期及输入框等几个控件的代码如下 
       <td style="width: 59px">
                                <span id="Label1" style="color:Black;font-size:10pt;">姓  名</span></td>
        <td style="width: 91px">
                                <input name="TextBox2" type="text" value="" maxlength="10" id="Text2" style="color:red;font-size:10pt;width:67px;" /></td>
       <td style="width: 58px">
                                <span id="Label2" style="color:Black;font-size:10pt;">性  别</span></td>
       <td colspan="2" style="width: 13px">
                               <select name="DropDownList1" onchange="javascript:setTimeout('__doPostBack(\'DropDownList1\',\'\')', 0)" id="DropDownList1" style="color:red;font-size:9pt;width:47px;">
<option selected="selected" value="1">男</option>
<option value="2">女</option> <td style="width: 56px">
                              <span id="Label4" style="color:Black;font-size:10pt;">身份证号</span></td>
 <td style="width: 37px">
                              <input name="TextBox3" type="text" value="" maxlength="18" onchange="javascript:setTimeout('__doPostBack(\'TextBox3\',\'\')', 0)" onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="TextBox3" style="color:red;font-size:10pt;width:127px;" /></td>
 <td style="width: 57px">
                           <span id="Label5" style="color:Black;font-size:10pt;">出生日期</span></td>
                            <input name="TextBox4" type="text" value="" maxlength="8" readonly="readonly" id="TextBox4" style="color:#0000C0;font-size:10pt;width:90px;" /></td>
                        </tr>
提交(确定)按钮的代码应怎样写才能把数据写入sql中bmb表的对应字段xm、xb、sfzh、csrq?请高手救救吧。

解决方案 »

  1.   

    insert into (xm、xb、sfzh、csrq) values(,,,,)
      

  2.   


    string sql = "insert into bmb(xm,xb,sfzh,csrq) values('"+ TextBox2.Text +"','"+DropDownList1.SelectedValue+"','"+TextBox3.Text+"','"+TextBox4.Text+"')";
      

  3.   


                StringBuilder strSql = new StringBuilder();
                strSql.Append("Insert Into bmb Values('");
                strSql.Append("'"+ TextBox 2 +"'"); //姓名
                  strSql.Append(",'"+ ...  +"'");   //同样方式追加进去...
                
             public int Execute(string strSql)
             {
                SqlConnection connection = new SqlConnection(connectionstr);
        SqlCommond commond = new SqlCommond (strSql,connection);
                if( connection == null ) throw new ArgumentNullException( "connection" );            // Create a command and prepare it for execution
                SqlCommand cmd = new SqlCommand();
                int retval             try
                {
                    // Finally, execute the command
                    retval= cmd.ExecuteNonQuery();
                    // Detach the SqlParameters from the command object, so they can be used again
                     connection.Close();
                    
                }
                catch
                {
                       throw;
                }
             }
    就是做插入操作...
      

  4.   

    自己写SqlConnection 连接数据库  用SqlCommand执行  上面的sql字符串就行
      

  5.   

    还没顾上试呢,先给分吧,不要嫌少啊,
    llsen,8
    lg3605119 ,4
    hanhanmj ,12
    非常感谢几位的无私帮助!