Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Posted
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()

Posted
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.
Posted

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.....

Proudly a Palestinian

Microsoft ASP.NET MVP

My Blog: wessamzeidan.net

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...