Sql server vb中的sql更新只能部分工作
我正在尝试通过VB2012更新MSSQLS2012中的表 如果我使用缺少4个字段的第一个代码,它会工作 使用附加的4个字段tire_id2、qty2、cost2、retail2,我得到错误: 无法将参数值从字符串转换为DateTime 好代码:Sql server vb中的sql更新只能部分工作,sql-server,visual-studio-2012,Sql Server,Visual Studio 2012,我正在尝试通过VB2012更新MSSQLS2012中的表 如果我使用缺少4个字段的第一个代码,它会工作 使用附加的4个字段tire_id2、qty2、cost2、retail2,我得到错误: 无法将参数值从字符串转换为DateTime 好代码: mycommand.Connection = m_cn mycommand.CommandText = "INSERT INTO sales (date, cust_id, tire_id, qty, cost_ea, retail_ea, p
mycommand.Connection = m_cn
mycommand.CommandText = "INSERT INTO sales (date, cust_id, tire_id, qty, cost_ea, retail_ea, plate,mileage,service,service2,serv_price,serv2_price,total,notes,custphone) VALUES (@date, @cust_id, @tire_id,@qty, @cost, @retail,@plate,@mileage,@service,@service2,@serv_price,@serv2_price,@total,@notes,@custphone)"
mycommand.Parameters.Add("@date", SqlDbType.Date).Value = txtQuoteDate.Text
mycommand.Parameters.Add("@cust_id", SqlDbType.NVarChar).Value = cust_datatable.Rows(0).Item("custID")
mycommand.Parameters.Add("@tire_id", SqlDbType.NVarChar).Value = (m_intRowPosition + 1)
mycommand.Parameters.Add("@qty", SqlDbType.VarChar).Value = txtQuantity.Text
mycommand.Parameters.Add("@cost", SqlDbType.VarChar).Value = m_DataTable.Rows(m_intRowPosition)("cost").ToString
mycommand.Parameters.Add("@retail", SqlDbType.NVarChar).Value = txtEachPrice.Text
mycommand.Parameters.Add("@plate", SqlDbType.VarChar).Value = txtplate.Text
mycommand.Parameters.Add("@mileage", SqlDbType.NVarChar).Value = txtmileage.Text
mycommand.Parameters.Add("@service", SqlDbType.NVarChar).Value = txtService1.Text
mycommand.Parameters.Add("@serv_price", SqlDbType.VarChar).Value = txtAlignPrice.Text
mycommand.Parameters.Add("@total", SqlDbType.NVarChar).Value = txtTotal.Text
mycommand.Parameters.Add("@notes", SqlDbType.NVarChar).Value = txtNotes.Text
mycommand.Parameters.Add("@custphone", SqlDbType.NVarChar).Value = txtCustPhone.Text
mycommand.Parameters.Add("@service2", SqlDbType.NVarChar).Value = txtService2.Text
mycommand.Parameters.Add("@serv2_price", SqlDbType.VarChar).Value = txtService2Price.Text
mycommand.ExecuteNonQuery()
错误代码:
mycommand.Connection = m_cn
mycommand.CommandText = "INSERT INTO sales (date, cust_id, tire_id,tire_id2, qty, qty2, cost_ea, cost_ea2, retail_ea, retail_e2, plate,mileage,service,service2,serv_price,serv2_price,total,notes,custphone) VALUES (@date, @cust_id, @tire_id, @tire_id2,@qty, @qty2, @cost, @cost2, @retail,@retail2,@plate,@mileage,@service,@service2,@serv_price,@serv2_price,@total,@notes,@custphone)"
mycommand.Parameters.Add("@date", SqlDbType.Date).Value = txtQuoteDate.Text
mycommand.Parameters.Add("@cust_id", SqlDbType.NVarChar).Value = cust_datatable.Rows(0).Item("custID")
mycommand.Parameters.Add("@tire_id", SqlDbType.NVarChar).Value = (m_intRowPosition + 1)
mycommand.Parameters.Add("@tire_id2", SqlDbType.NVarChar).Value = (m_introwposition2 + 1)
mycommand.Parameters.Add("@qty", SqlDbType.VarChar).Value = txtQuantity.Text
mycommand.Parameters.Add("@qty2", SqlDbType.VarChar).Value = txtQuantity2.Text
mycommand.Parameters.Add("@cost", SqlDbType.VarChar).Value = m_DataTable.Rows(m_intRowPosition)("cost").ToString
mycommand.Parameters.Add("@cost2", SqlDbType.VarChar).Value = m_datatable2.Rows(m_introwposition2)("cost").ToString
mycommand.Parameters.Add("@retail", SqlDbType.NVarChar).Value = txtEachPrice.Text
mycommand.Parameters.Add("@retail2", SqlDbType.NVarChar).Value = txtEachPrice2.Text
mycommand.Parameters.Add("@plate", SqlDbType.VarChar).Value = txtplate.Text
mycommand.Parameters.Add("@mileage", SqlDbType.NVarChar).Value = txtmileage.Text
mycommand.Parameters.Add("@service", SqlDbType.NVarChar).Value = txtService1.Text
mycommand.Parameters.Add("@serv_price", SqlDbType.VarChar).Value = txtAlignPrice.Text
mycommand.Parameters.Add("@total", SqlDbType.NVarChar).Value = txtTotal.Text
mycommand.Parameters.Add("@notes", SqlDbType.NVarChar).Value = txtNotes.Text
mycommand.Parameters.Add("@custphone", SqlDbType.NVarChar).Value = txtCustPhone.Text
mycommand.Parameters.Add("@service2", SqlDbType.NVarChar).Value = txtService2.Text
mycommand.Parameters.Add("@serv2_price", SqlDbType.VarChar).Value = txtService2Price.Text
mycommand.ExecuteNonQuery()
有什么想法吗?
下面是我对sql表的CREATE语句:
CREATE TABLE [dbo].[sales](
[date] [date] NULL,
[cust_id] [int] NULL,
[tire_id] [int] NULL,
[qty] [int] NULL,
[cost_ea] [decimal](5, 2) NULL,
[retail_ea] [decimal](5, 2) NULL,
[plate] [nchar](10) NULL,
[mileage] [nchar](10) NULL,
[service] [nchar](30) NULL,
[serv_price] [nchar](10) NULL,
[total] [nchar](10) NULL,
[notes] [nvarchar](150) NULL,
[custphone] [nchar](10) NULL,
[service2] [nchar](30) NULL,
[serv2_price] [nchar](10) NULL,
[inv_no] [int] IDENTITY(1,1) NOT NULL,
[tire_id2] [int] NULL,
[qty2] [int] NULL,
[cost_ea2] [decimal](5, 2) NULL,
[retail_ea2] [decimal](5, 2) NULL,
[tire_id3] [int] NULL,
[qty3] [int] NULL,
[cost_ea3] [decimal](5, 2) NULL,
[retail_ea3] [decimal](5, 2) NULL,
CONSTRAINT [PK_sales] PRIMARY KEY CLUSTERED)
在这条线上
mycommand.Parameters.Add("@date", SqlDbType.Date).Value = txtQuoteDate.Text
请试试这个
mycommand.Parameters.Add("@date", SqlDbType.Date).Value = cDate(txtQuoteDate.Text)
你的销售表的定义是什么。将您的创建表语法添加到您的问题中。我已经添加了CREATE语句,谢谢您的回答!