I am a beginner to asp.net and i was trying to crate a web page thta registers users in sql database and i got this error massage pls help???
Insert Error:Incorrect syntax near the keyword 'Full'.<br />
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.<br />
<br />
Exception Details: System.Exception: Insert Error:Incorrect syntax near the keyword 'Full'.<br />
<br />
Source Error:<br />
<br />
Line 66: string msg = "Insert Error:";<br />
Line 67: msg += ex.Message;<br />
Line 68: throw new Exception(msg);<br />
Line 69: }<br />
Line 70: finally <br />
thank u all for trying to help i am kind of new here.here is the C# code
here is the improved question
i have two text boxes named name and lastname and a submit button in an ~\Test\trial.aspx page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class Test_trail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private void ExecuteInsert(string name, string username) {
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source = .\sqlexpress;" +
"Database =Test ; Integrated Security=True";
string sql = "INSERT INTO Test (name, username)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[7];
param[0] = new SqlParameter("@name", System.Data.SqlDbType.VarChar, 50);
param[1] = new SqlParameter("@Uusername",System.Data.SqlDbType.VarChar,50);
param[0].Value = username;
param[1].Value = username;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
cmd.Parameters.Add("@name", System.Data.SqlDbType.VarChar).Value = txtfname;
cmd.Parameters.Add("@Uusername", System.Data.SqlDbType.VarChar).Value = txtlname;
}
cmd.CommandType = System.Data.CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void sub_Click(object sender, EventArgs e)
{
ExecuteInsert(txtfname.Text,
txtlname.Text);
Response.Write("Record was successfully added!");
ClearControls(Page);
}
public static void ClearControls(Control Parent){
if (Parent is TextBox)
{ (Parent as TextBox).Text = string.Empty; }
else
{
foreach (Control c in Parent.Controls)
ClearControls(c);
}
}
}