未处理 System.Data.SqlClient.SqlException
Message="')' 附近有语法错误。"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=15
LineNumber=1
Number=102
Procedure=""
Server="PC-201002231828\\SQLEXPRESS"
State=1
StackTrace:
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在 myqq.RegistForm.btb_regist_Click(Object sender, EventArgs e) 位置 D:\My Documents\Visual Studio 2008\Projects\myqq\myqq\RegistForm.cs:行号 196
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 myqq.Program.Main() 位置 D:\My Documents\Visual Studio 2008\Projects\myqq\myqq\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
怎么看 错在哪里
Message="')' 附近有语法错误。"
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060
Class=15
LineNumber=1
Number=102
Procedure=""
Server="PC-201002231828\\SQLEXPRESS"
State=1
StackTrace:
在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
在 System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
在 System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
在 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
在 myqq.RegistForm.btb_regist_Click(Object sender, EventArgs e) 位置 D:\My Documents\Visual Studio 2008\Projects\myqq\myqq\RegistForm.cs:行号 196
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 myqq.Program.Main() 位置 D:\My Documents\Visual Studio 2008\Projects\myqq\myqq\Program.cs:行号 18
在 System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
怎么看 错在哪里
在 myqq.RegistForm.btb_regist_Click(Object sender, EventArgs e) 位置 D:\My Documents\Visual Studio 2008\Projects\myqq\myqq\RegistForm.cs:行号 196
Message="')' 附近有语法错误。"
说的很清楚了
在 myqq.RegistForm.btb_regist_Click(Object sender, EventArgs e) 位置 D:\My Documents\Visual Studio 2008\Projects\myqq\myqq\RegistForm.cs:行号 196
{
starId = getstarId();
bloodTypeId = getbloodId();
sqlcmd = string.Format("insert into users(LoginPwd, NickName, Sex, Age, Name, StarId, BloodTypeId)values('{0}','{1}','{2}',{3},'{4}',{5},{6})",txt_Pwd.Text.Trim(),txt_NickName.Text.Trim(),sex,int.Parse(txt_Age.Text),txt_RealName.Text.Trim(),starId,bloodTypeId) ;
}
else if (cbx_Blood.Text == "" && cbx_stars.Text != "")
{
starId = getstarId();
sqlcmd = string.Format("insert into users(LoginPwd, NickName, Sex, Age, Name, StarId,)values('{0}','{1}','{2}',{3},'{4}',{5})", txt_Pwd.Text.Trim(), txt_NickName.Text.Trim(), sex, int.Parse(txt_Age.Text), txt_RealName.Text.Trim(), starId);
}
else if (cbx_Blood.Text != "" && cbx_stars.Text == "")
{
bloodTypeId = getbloodId();
sqlcmd = string.Format("insert into users(LoginPwd, NickName, Sex, Age, Name, BloodTypeId)values('{0}','{1}','{2}',{3},'{4}',{5})", txt_Pwd.Text.Trim(), txt_NickName.Text.Trim(), sex, int.Parse(txt_Age.Text), txt_RealName.Text.Trim(), bloodTypeId);
}
else
{
sqlcmd = string.Format("insert into users(LoginPwd, NickName, Sex, Age, Name)values('{0}','{1}','{2}',{3},'{4}')", txt_Pwd.Text.Trim(), txt_NickName.Text.Trim(), sex, int.Parse(txt_Age.Text), txt_RealName.Text.Trim());
}
try
{
SqlCommand cmd = new SqlCommand(sqlcmd,DBHelper.sqlconn);
DBHelper.sqlconn.Open();
if (cmd.ExecuteNonQuery()==1)
{
sqlcmd = "SELECT @@Identity FROM Users ";
cmd.CommandText = sqlcmd;
qqnum = Convert.ToInt32(cmd.ExecuteScalar());
DBHelper.Registnum = Convert.ToInt32(cmd.ExecuteScalar());
}
else
{
message = "注册失败";
}
}
catch (Exception ex)
{
error = true;
message = "服务器出现意外错误!稍后重试";
MessageBox.Show(ex.Message);
throw;
else两个条件都没错。但是我combox 选择1个 1个不选 就报错了
说明满足else if的判断 所以是else if里的错误码?
bloodTypeId = getbloodId();
两个写在外面的方法 从服务器获得Id。
应该没有错,因为 if 和 else都可以成功插入正确的id数字!
sqlcmd = string.Format("insert into users(LoginPwd, NickName, Sex, Age, Name, StarId,)values('{0}','{1}','{2}',{3},'{4}',{5})", txt_Pwd.Text.Trim(), txt_NickName.Text.Trim(), sex, int.Parse(txt_Age.Text), txt_RealName.Text.Trim(), starId); 改成
sqlcmd = string.Format("insert into users(LoginPwd, NickName, Sex, Age, Name, StarId)values('{0}','{1}','{2}',{3},'{4}',{5})", txt_Pwd.Text.Trim(), txt_NickName.Text.Trim(), sex, int.Parse(txt_Age.Text), txt_RealName.Text.Trim(), starId);values前多了一个逗号
上联:为API生,为框架死,为debug奋斗一辈子下联:吃符号的亏,上大小写的当,最后死在需求上!横批:杯具程序员