Error inserting data in table

60 pts.
Tags:
ASP.NET
C#
GridView
SQL
hi plz help me ,i want to insert some data in a table but some error ocurred. --------------------------------------------------------------- using System; using System.Data.SqlClient; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; public partial class _Default : System.Web.UI.Page { SqlConnection con; SqlDataAdapter da; SqlCommand cmd; System.Data.DataTable dt; protected void Page_Load(object sender, EventArgs e) { con = new SqlConnection("server=serv2005;integrated security=SSPI;uid=sa;pwd=sa;database=rswm"); da = new SqlDataAdapter("select * from login",con); //gd = new GridView(); dt = new DataTable(); da.Fill(dt); GridView1.DataSource = dt; } protected void Button2_Click1(object sender, EventArgs e) { //string str="Insert into login(username,password)values(@username,@password)"; cmd = new SqlCommand(); cmd.CommandText = "insert into login values(" + TextBox4.Text + "," + TextBox5.Text + ")"; //cmd.Parameters.Add(new SqlParameter("username", SqlDbType.VarChar)).value = TextBox4.Text; //cmd.Parameters.Add(new SqlParameter("password", SqlDbType.VarChar)).value = TextBox5.Text; cmd.Connection = con; cmd.Connection.Open(); cmd.ExecuteNonQuery(); //dt.Clear(); da.Fill(dt); GridView1.DataSource = dt; cmd.Connection.Close(); } }

Answer Wiki

Thanks. We'll let you know when a new response is added.

Without the error message no one will be able to tell you what the problem is.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Denny Cherry
    What error message are you getting?
    66,360 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following