Placeholder
-
Hello Im must read records from Gridview and then insert them to database. Here is the code that I wrote.
for (int i = 0; i<counter; i++) { string ID = GridView.Rows[i].Cells[0].Text; objDataAdapter.SelectCommand.CommandText = "INSERT INTO MYTable " + "(Name) VALUES(@Name)"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@Name",Name); }
There is an exception:The variable name '@Name' has already been declared. Variable names must be unique within a query batch or stored procedure.
Please help me how can I handle this exception. -
Hello Im must read records from Gridview and then insert them to database. Here is the code that I wrote.
for (int i = 0; i<counter; i++) { string ID = GridView.Rows[i].Cells[0].Text; objDataAdapter.SelectCommand.CommandText = "INSERT INTO MYTable " + "(Name) VALUES(@Name)"; objDataAdapter.SelectCommand.Parameters.AddWithValue("@Name",Name); }
There is an exception:The variable name '@Name' has already been declared. Variable names must be unique within a query batch or stored procedure.
Please help me how can I handle this exception.Does this happen the first time through, or the second ? Why would you make the 'select command' do an insert ? Why not just run the SQL directly without using a data adapter ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Does this happen the first time through, or the second ? Why would you make the 'select command' do an insert ? Why not just run the SQL directly without using a data adapter ?
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
OK, that's what I suspected, because it's a member object, you're setting the parameter over and over, that's why I asked if it happens the first time. I think those data adapter things are retarded, I never use them.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
OK, that's what I suspected, because it's a member object, you're setting the parameter over and over, that's why I asked if it happens the first time. I think those data adapter things are retarded, I never use them.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
-
Christian Graus wrote:
I think those data adapter things are retarded, I never use them.
What do you use instead of adapter?
I write a proper data layer, in a seperate dll, I NEVER put SQL in the presentation layer, and I'd fire anyone who worked for me who did.
Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.