Showing posts with label declared. Show all posts
Showing posts with label declared. Show all posts

Monday, March 19, 2012

Help! How to insert multiple rows into Database??

I keep getting this error but it will only insert the 1st row into my database table

The variable name '@.CustId' has already been declared. Variable names must be unique within a query batch or stored procedure.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs)

Dim drow As GridViewRow

For Each drow In GridView1.Rows

Dim textBoxText As String = CType(drow.FindControl("Label2"), Label).Text

SqlDataSource2.InsertParameters.Add("CustId", TypeCode.String, Profile.UserName)

SqlDataSource2.InsertParameters.Add("OrderDate", TypeCode.DateTime, DateTime.Now.ToString)

SqlDataSource2.InsertParameters.Add("Total", TypeCode.Double, TotalUnitPrice)

SqlDataSource2.InsertParameters.Add("Quantity", TypeCode.Int32, textBoxText)

SqlDataSource2.Insert()

Next

Response.Redirect("checkout.aspx")

End Sub

since you are operating in a loop, you should clear your parameters collection on each pass through

Dim drowAs GridViewRowFor Each drowIn GridView1.RowsDim textBoxTextAs String =CType(drow.FindControl("Label2"), Label).Text SqlDataSource2.InsertParameters.Clear()'<-- Clear the params first SqlDataSource2.InsertParameters.Add("CustId", TypeCode.String, Profile.UserName) SqlDataSource2.InsertParameters.Add("OrderDate", TypeCode.DateTime, DateTime.Now.ToString) SqlDataSource2.InsertParameters.Add("Total", TypeCode.Double, TotalUnitPrice) SqlDataSource2.InsertParameters.Add("Quantity", TypeCode.Int32, textBoxText) SqlDataSource2.Insert()Next
|||

Try this after your insert:

SqlDataSources2.InsertParameters.Clear();

There is another way to do this. Declare your parameters first, then assign the InsertParameters' default values for each InsertParameter after the insert.

SqlDataSource2.InsertParameters("Parameter1").DefaultValue=valueofParameter1

...

|||Omg .. thanks a lot ! It works... Haha ...

Wednesday, March 7, 2012

HELP! " the table schema changed after the cursor was declared"

I have a DTS package working from backend and command line. Then I did an enhancement. It works from backend but not from command line. The error says:

Step Error Description:Could not complete cursor operation because the table schema changed after the cursor was declared.

But I don't see "table schema" change?!! Any idea?

Thanks,

LiliOriginally posted by lili3000
I have a DTS package working from backend and command line. Then I did an enhancement. It works from backend but not from command line. The error says:

Step Error Description:Could not complete cursor operation because the table schema changed after the cursor was declared.

But I don't see "table schema" change?!! Any idea?

Thanks,

Lili

I ran in to the same problem. As it turned out I was running the application at 1:00 am to process credit card transaction (This application is a batched response from shipper) Anyway. I had inadvertly schedule maintence during this time. The problem was resolved by moving the Maintence time.

I hope this helps.

Terry