I know this has been asked numerous times, but they all involved statements much more complicated than mine. I couldn't figure out my problem from the other posts.I am about as close to a newbie as you can get...I am using MS SQL Server 2008R2 along with VB 2010.The first question is: why is it even trying to convert anything to numeric? I have NO numeric data types. And I don't have any nvarchar data types either. I'm very confused.What am I doing wrong? Doesn't nchar include any and all characters, in any combination? Should I change everything to text data type? Maybe something else?Some values are going to be blank. The Lab/Source Lots have numbers, letters and dashes.My stored procedure:ALTER PROCEDURE dbo.MChemsInsert ( @LabLot nchar(10), @Chem nchar(50), @Source nchar(50), @SourceLot nchar(10), @ExpireDt date, @OpenDt nchar(10), @Opener nchar(10), @DisposeDt nchar(10), @Disposer nchar(10), @RecdDt date ) AS SET NOCOUNT OFF; INSERT INTO [MChems]([LabLot], [Chem], [Source], [SourceLot], [ExpireDt], [OpenDt], [Opener], [DisposeDt], [Disposer], [RecdDt])VALUES (@LabLot, @Chem, @Source, @SourceLot, @ExpireDt, @OpenDt, @Opener, @DisposeDt, @Disposer, @RecdDt) SELECT LabLot, Chem, Source, SourceLot, ExpireDt, OpenDt, Opener, DisposeDt, Disposer, RecdDtFROM [MChems]WHERE (LabLot = SCOPE_IDENTITY())
I believe the query builder came up with that code.I have tried entering "NULL" for all the blank values, but the error converting data type nvarchar to numeric always shows.The VB code I am using, if that is helpful: sqlCon = New SqlConnection(strConn) Using (sqlCon) Dim sqlComm2 As New SqlCommand() sqlComm2.Connection = sqlCon sqlComm2.CommandText = "MChemsInsert" sqlComm2.CommandType = CommandType.StoredProcedure sqlComm2.Parameters.AddWithValue("LabLot", txtLabLot.Text) sqlComm2.Parameters.AddWithValue("Chem", txtChem.Text) sqlComm2.Parameters.AddWithValue("Source", txtSource.Text) sqlComm2.Parameters.AddWithValue("SourceLot", txtSourceLot.Text) sqlComm2.Parameters.AddWithValue("ExpireDt", txtExp.Text) sqlComm2.Parameters.AddWithValue("OpenDt", txtOpen.Text) sqlComm2.Parameters.AddWithValue("Opener", cboOpen.Text) sqlComm2.Parameters.AddWithValue("DisposeDt", txtDispose.Text) sqlComm2.Parameters.AddWithValue("Disposer", cboDispose.Text) sqlComm2.Parameters.AddWithValue("RecdDt", txtRecd.Text) sqlCon.Open() sqlComm2.ExecuteNonQuery() sqlCon.Close() End Using
Thank you so much for any and all help.