legendgod Posted June 25, 2004 Posted June 25, 2004 I want to insert a new record to a table, the table have 8 columns. The Primary Key "schId" which is an auto-increment number is ignored. Therefore I created the follow stored procedure: CREATE PROCEDURE [dbo].[scheduleAddItem] @startDT smalldatetime, @endDT smalldatetime, @Note varchar, @sAlias varchar, @hName varchar, @cName varchar AS INSERT INTO Schedule (schStartTime, schEndTime, schNote, sId, hId, cId, schPending) VALUES (@startDT, @endDT, @Note, @sAlias, @hName, @cName, 5) GO In my aspx page I typed the following: ' startDT & endDT are datetime variable, NoteTextBox is a textbox control, the else are string variable DBCommand.Parameters.Add(New SqlParameter("@startDT",SqlDbType.smalldatetime, startDT)) DBCommand.Parameters.Add(New SqlParameter("@endDT",SqlDbType.smalldatetime, endDT)) DBCommand.Parameters.Add(New SqlParameter("@Note", SqlDbType.varchar, Replace(NoteTextBox.Text, "'", "''"))) DBCommand.Parameters.Add(New SqlParameter("@sAlias",SqlDbType.varchar, sAliasDropList.SelectedValue)) DBCommand.Parameters.Add(New SqlParameter("@hName",SqlDbType.varchar, hNameDropList.SelectedValue)) DBCommand.Parameters.Add(New SqlParameter("@cName",SqlDbType.varchar, cNameDropList.SelectedValue)) However, when I run the aspx, the dotNet framework return a error said the stored procedure contain error. Which part I am wrong with? Am I wrong in ignore to input the Primary key value?Any idea is helpful. Thank you. Quote http://blog.legendgod.com
JABE Posted June 26, 2004 Posted June 26, 2004 Can you post the error message? Problem may not be related to the primary key field at all. Quote
legendgod Posted June 26, 2004 Author Posted June 26, 2004 Can you post the error message? Problem may not be related to the primary key field at all. Because I am using traditional Chinese Framework it gives non-English error message. 'ScheduleAddItem' is my stored procedure. The translation could be ..... : row 1: statement around 'ScheduleAddItem' incorrect. Expection detail: System.Data.SqlClient.SqlException: Row 1: statement around 'ScheduleAddItem' incorrect. source code error: Row 72: ' ")" Row 73: Row 74: DBCommand.ExecuteNonQuery Row 75: 'DBConnection.Close() Row 76: Conn.Close() Quote http://blog.legendgod.com
JABE Posted June 26, 2004 Posted June 26, 2004 Everthing seems OK, except for that line Row 72: ' ")". Any idea where that came from? Anyway, if that's not the root of the problem, try using Profiler to inspect the actual SQL statements passed by SqlClient to SQL Server. Might be some translation issues. Quote
legendgod Posted June 26, 2004 Author Posted June 26, 2004 Please forgive my know-nothing, what is Profiler? Is it a class in DotNet of a term? Quote http://blog.legendgod.com
wessamzeidan Posted June 26, 2004 Posted June 26, 2004 INSERT INTO Schedule (schStartTime, schEndTime, schNote, sId, hId, cId, schPending) VALUES (@startDT, @endDT, @Note, @sAlias, @hName, @cName, 5) I'm not sure, but what is the type of hId and cId, they seem IDs to me, and you're assigning string values to them, @hName and @cName. Can you post the structure of your table..... Quote Proudly a Palestinian Microsoft ASP.NET MVP My Blog: wessamzeidan.net
legendgod Posted June 26, 2004 Author Posted June 26, 2004 Problem solved... some ppl told me that I missed the following 2 statement: DBCommand.CommandType=CommandType.StoredProcedure DBCommand.CommandText="ScheduleAddItem" Thank you for all your support anyway! Quote http://blog.legendgod.com
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.