首页 > 解决方案 > 尝试将值插入本地数据库时出现运行时错误

问题描述

<asp:TextBox ID="txtfrname" runat="server" placeholder="First Name" Height="25px" Width="250px">
<asp:TextBox ID="txtlaname" runat="server" placeholder="Last Name" Height="25px" Width="250px" />
<asp:TextBox ID="txtmob" runat="server" placeholder="Mobile Number" TextMode="Number" Height="25px" Width="250px"></asp:TextBox>
<asp:Button ID="Signup" runat="server" Class="btn" OnClientClick="validate()" OnClick="Signup_Click" Text="Register" style="width:120px; height:35px;font-weight:normal;font-family:Arial; font-size:small; color:white; background-color:#ff4500; border-width:0PX; border-style:None" onmouseover="this.style.backgroundColor='#ff6933';return true;"  onmouseout="this.style.backgroundColor='#ff4500'; return true;" />

C#代码:

protected void Signup_Click(Object sender, EventArgs e)
{
    string s1 = txtfrname.Text;
    string s2 = txtlaname.Text;
    string s3 = txtmob.Text;             

    long a = Convert.ToInt64(s3);

    string sql = "insert into Register values('" + s1 + "','" + s2 + "'," + a + ")";

    SqlConnection con = mydb.mycon();
    SqlCommand com = new SqlCommand(sql, con);

    con.Open();
    com.ExecuteNonQuery();
    con.Close();    

    Response.Redirect("account.aspx");
}

标签: asp.netsql-server-2012

解决方案


推荐阅读