using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=JAZMINTOIN\\SQLEXPRESS;Initial Catalog=asp;Integrated Security=True");
string sql=string.Format("Insert into Login values('{0}','{1}')",TextBox1.Text,TextBox2.Text);
con.Open();
SqlCommand cmd =new SqlCommand(sql,con);
//ExecuteNonQuery = used for insert/update/delete
cmd.ExecuteNonQuery();
Label3.Text ="Thank You for Registering";
}
i able to get the Thank You for Registering but sumthing error in the connection part such con.Open();
Column name or number of supplied values does not match table definition.
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.
Exception Details: System.Data.SqlClient.SqlException: Column name or number of supplied values does not match table definition.
Source Error:
Line 26: con.Open();
Line 27: SqlCommand cmd = new SqlCommand(sql, con);
Line 28: cmd.ExecuteNonQuery(); Line 29: Label3.Text = "Thank You for Registering";
Line 30:
Source File: c:\Users\Jc\Documents\Visual Studio 2008\WebSites\WebSite49\Default.aspx.cs Line:
28
Stack Trace:
[SqlException (0x80131904): Column name or number of supplied values does not match table definition.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1951450
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4849003
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2394
System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) +192
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +317
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +137
_Default.Button1_Click(Object sender, EventArgs e) in c:\Users\Jc\Documents\Visual Studio 2008\WebSites\WebSite49\Default.aspx.cs:28
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
ASP .jASON
0 Points
30 Posts
Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:08 AM|LINK
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Data.Sql;
public partial class Default5 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=JAZMINTOIN\\SQLEXPRESS;Initial Catalog=asp;Integrated Security=True");
string sql=string.Format("Insert into Login values('{0}','{1}')",TextBox1.Text,TextBox2.Text);
con.Open();
SqlCommand cmd =new SqlCommand(sql,con);
//ExecuteNonQuery = used for insert/update/delete
cmd.ExecuteNonQuery();
Label3.Text ="Thank You for Registering";
}
i able to get the Thank You for Registering but sumthing error in the connection part such con.Open();
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:15 AM|LINK
what you are doing is right , try to close connection after finishing execution.
ASP .jASON
0 Points
30 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:26 AM|LINK
Column name or number of supplied values does not match table definition.
cmd.ExecuteNonQuery();
How to fix it
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:31 AM|LINK
change your sql to this
INSERT into Login(column1Name, column2Name) VALUES('" +TextBox1.Text + "', '" + TextBox2.Text +"');
ASP .jASON
0 Points
30 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:32 AM|LINK
Server Error in '/WebSite49' Application.
Column name or number of supplied values does not match table definition.
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.
Exception Details: System.Data.SqlClient.SqlException: Column name or number of supplied values does not match table definition.
Source Error:
Line 26: con.Open(); Line 27: SqlCommand cmd = new SqlCommand(sql, con); Line 28: cmd.ExecuteNonQuery(); Line 29: Label3.Text = "Thank You for Registering"; Line 30:Source File: c:\Users\Jc\Documents\Visual Studio 2008\WebSites\WebSite49\Default.aspx.cs Line: 28
Stack Trace:
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:43 AM|LINK
have you tried the sql statement that i wrote in my last post ?
ASP .jASON
0 Points
30 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:43 AM|LINK
Also cannot
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:46 AM|LINK
can i know what is your column names and their types please
ASP .jASON
0 Points
30 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:52 AM|LINK
create table jc(name varchar (50), id int)
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Why i cannot update MySQL by using asp.net 3.5
Jun 03, 2012 08:56 AM|LINK
if your table name is jc why you are inserting into login?? and the id is integer and you are entering text which is string
Int id = convert.toInt32(TextBox2.text);
insert into table jc (name , id) values('" + Textbox1.text + "', " + id + ")";