يه مشكل توي asp.net

آقا مشكل اين چيه؟
من وقتي مي خواهم يه سري اطلاعات وارد ديتابيس كنم اين مشكل رو مي ده.
کد:
Server Error in '/WebApplication2' Application.
--------------------------------------------------------------------------------

Line 1: Incorrect syntax near ','. 
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: Line 1: Incorrect syntax near ','.

Source Error: 


Line 92: 
Line 93: 			sqlcommandUsers.Connection.Open();
Line 94: 			sqlcommandUsers.ExecuteNonQuery();	
Line 95: 			sqlcommandUsers.Connection.Close();
Line 96: 
 

Source File: c:\inetpub\wwwroot\webapplication2\webform1.aspx.cs    Line: 94 

Stack Trace: 


[SqlException: Line 1: Incorrect syntax near ','.]
   System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   WebApplication2.WebForm1.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplication2\webform1.aspx.cs:94
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   System.Web.UI.Page.ProcessRequestMain()

 


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:1.0.3705.0; ASP.NET Version:1.0.3705.0
 

a_mollaei

Member
احتمال خيلي زياد توي Queryاي كه نوشتي مشكل داري.

كدتو بذار ببينيم چيه.
 
اينم كد

اينه
کد:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;  
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace ex02
{
	/// <summary>
	/// Summary description for WebForm1.
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.Label Label2;
		protected System.Web.UI.WebControls.Label Label3;
		protected System.Web.UI.WebControls.Label Label4;
		protected System.Web.UI.WebControls.Label Label5;
		protected System.Web.UI.WebControls.Label Label6;
		protected System.Web.UI.WebControls.Label Label7;
		protected System.Web.UI.WebControls.Label Label8;
		protected System.Web.UI.WebControls.Label Label9;
		protected System.Web.UI.WebControls.Label Label10;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
		protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
		protected System.Web.UI.WebControls.TextBox txtName;
		protected System.Web.UI.WebControls.TextBox txtEmail;
		protected System.Web.UI.WebControls.TextBox txtPassWord;
		protected System.Web.UI.WebControls.TextBox txtAddress;
		protected System.Web.UI.WebControls.TextBox txtCity;
		protected System.Web.UI.WebControls.TextBox txtState;
		protected System.Web.UI.WebControls.TextBox txtPostalCode;
		protected System.Web.UI.WebControls.TextBox txtCountry;
		protected System.Web.UI.WebControls.TextBox txtPhone;
		protected System.Web.UI.WebControls.TextBox txtFax;
		protected System.Web.UI.WebControls.TextBox txtSig;
		protected System.Web.UI.WebControls.Button btnSend;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Label Label11;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void btnSend_Click(object sender, System.EventArgs e)
		{
			SqlConnection sqlconnectionForum = 
				new SqlConnection("server=(local);uid=sa;pwd=;database=AspNetForum");
			SqlDataAdapter sqldataadapterUsers = 
				new SqlDataAdapter("select * from tblUsers", sqlconnectionForum);

			String insertCmd =
				"INSERT INTO tblUsers(user_type_id, user_name, email,"+
				"password, addr1, city, state, postalcode, country,"+
				"phone,fax,signature) VALUES("+
				 "0,"+
				 txtName.Text.Trim() +","+ txtEmail.Text.Trim()+","+txtPassWord.Text.Trim()+","+    
				 txtAddress.Text.Trim() +","+ txtCity.Text.Trim()+","+txtState.Text.Trim()+","+
				 txtPostalCode.Text.Trim() +","+ txtCountry.Text.Trim()+","+txtPhone.Text.Trim()+","+
				 txtFax.Text.Trim() +","+ txtSig.Text.Trim() +  ")";

			SqlCommand sqlcommandUsers = new SqlCommand(insertCmd, sqlconnectionForum);

			sqlcommandUsers.Connection.Open();
			sqlcommandUsers.ExecuteNonQuery();	
			sqlcommandUsers.Connection.Close();

			DataSet datasetUsers = new DataSet();
			sqldataadapterUsers.Fill(datasetUsers, "tblUsers");

			DataGrid1.DataSource=datasetUsers.Tables["tblUsers"].DefaultView;
			DataGrid1.DataBind();

		}
	}
}
 

a_mollaei

Member
كدت مشكل داره.

شما موقع Insert كردن بايد حتما دو طرف Value علامت ' رو قرار بدي.

اين كدو بذار ببين كار مي كنه؟

کد:
.
..


string insertCmd = 
            "INSERT INTO tblUsers(user_type_id, user_name, email,"+ 
            "password, addr1, city, state, postalcode, country,"+ 
            "phone,fax,signature) VALUES('"+ 
             "0','"+ 
             txtName.Text.Trim() +"','"+ txtEmail.Text.Trim()+"','"+txtPassWord.Text.Trim()+"','"+    
             txtAddress.Text.Trim() +"','"+ txtCity.Text.Trim()+"','"+txtState.Text.Trim()+"','"+ 
             txtPostalCode.Text.Trim() +"','"+ txtCountry.Text.Trim()+"','"+txtPhone.Text.Trim()+"','"+ 
             txtFax.Text.Trim() +"','"+ txtSig.Text.Trim() +  "')";


.
..
 

جدیدترین ارسال ها

بالا