问题描述
小弟我刚学,不懂这个,贴出来请各位前辈帮忙,以下是我写的代码,关键的地方,我以红色标注,这些地方应该怎么改呢:MySql="InsertIntoEquipment(C_EquipmentSerialNumber,"&_"C_EquipmentName,"&_"C_EquipmentModel,"&_"C_IP,"&_"C_Price,"&_"C_mainboard,"&_"C_CPU,"&_"C_HandDisk,"&_"C_Memory,"&_"C_Display,"&_"C_CDRom,"&_"C_SoundCard,"&_"C_WebCard,"&_"C_DisplayCard,"&_"C_BuyDate,"&_"C_UserName,"&_"C_Dept,"&_"C_Sell,"&_"C_Tel,"&_"C_Remark,"&_"C_Booker,"&_"C_EnterDate)"&_"Values(@C_EquipmentSerialNumber,"&_"@C_EquipmentName,"&_"@C_EquipmentModel,"&_"@C_IP,"&_"@C_Price,"&_"@C_mainboard,"&_"@C_CPU,"&_"@C_HandDisk,"&_"@C_Memory,"&_"@C_Display,"&_"@C_CDRom,"&_"@C_SoundCard,"&_"@C_WebCard,"&_"@C_DisplayCard,"&_"@C_BuyDate,"&_"@C_UserName,"&_"@C_Dept,"&_"@C_Sell,"&_"@C_Tel,"&_"@C_Remark,"&_"@C_Booker,"&_"@C_EnterDate)"MyComm=NewOleDbCommand(MySql,MyConn)MyComm.Parameters.Add(NewOleDbParameter("@C_EquipmentSerialNumber",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_EquipmentName",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_EquipmentModel",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_IP",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Price",OleDbType.Currency))MyComm.Parameters.Add(NewOleDbParameter("@C_mainboard",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_CPU",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_HandDisk",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Memory",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Display",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_CDRom",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_SoundCard",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_WebCard",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_DisplayCard",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_BuyDate",OleDbType.DBDate))MyComm.Parameters.Add(NewOleDbParameter("@C_UserName",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Dept",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Sell",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Tel",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_Remark",OleDbType.VarChar))MyComm.Parameters.Add(NewOleDbParameter("@C_Booker",OleDbType.Char,50))MyComm.Parameters.Add(NewOleDbParameter("@C_EnterDate",OleDbType.DBDate))MyComm.Parameters("@C_EquipmentSerialNumber").Value=EquipmentSerialNumber.TextMyComm.Parameters("@C_EquipmentName").Value=EquipmentName.TextMyComm.Parameters("@C_EquipmentModel").Value=EquipmentModel.TextMyComm.Parameters("@C_IP").Value=IP.TextIfPrice.Text=""ThenMyComm.Parameters("@C_Price").Value=""ElseMyComm.Parameters("@C_Price").Value=Price.TextEndIfMyComm.Parameters("@C_mainboard").Value=mainboard.TextMyComm.Parameters("@C_CPU").Value=CPU.TextMyComm.Parameters("@C_HandDisk").Value=HandDisk.TextMyComm.Parameters("@C_Memory").Value=Memory.TextMyComm.Parameters("@C_Display").Value=Display.TextMyComm.Parameters("@C_CDRom").Value=CDRom.TextMyComm.Parameters("@C_SoundCard").Value=SoundCard.TextMyComm.Parameters("@C_WebCard").Value=WebCard.TextMyComm.Parameters("@C_DisplayCard").Value=DisplayCard.TextIfBuyDate.Text=""ThenMyComm.Parameters("@C_BuyDate").Value=""ElseMyComm.Parameters("@C_BuyDate").Value=FormatCurrency(BuyDate.Text)EndIfMyComm.Parameters("@C_UserName").Value=UserName.TextMyComm.Parameters("@C_Dept").Value=Dept.TextMyComm.Parameters("@C_Sell").Value=Sell.TextMyComm.Parameters("@C_Tel").Value=Tel.TextMyComm.Parameters("@C_Remark").Value=Remark.TextMyComm.Parameters("@C_Booker").Value="admin"MyComm.Parameters("@C_EnterDate").Value=Now()
解决方案
解决方案二:
IfPrice.Text=""ThenMyComm.Parameters("@C_Price").Value="0.0"ElseMyComm.Parameters("@C_Price").Value=Price.TextEndIfIfBuyDate.Text=""ThenMyComm.Parameters("@C_BuyDate").Value="1900-01-01"ElseMyComm.Parameters("@C_BuyDate").Value=FormatCurrency(BuyDate.Text)EndIf或者你在数据库的表里为这两个字段设置默认值