Bunch's Blog

One day I'll have a catchy subtitle, one day
posts - 77, comments - 89, trackbacks - 0

My Links

News

Tag Cloud

Archives

Green

Friday, October 02, 2009

Updating Parameter Check

Every now and again you may come across an error when trying to update a database from a data driven control (i.e. gridview, formview) that is tied to a SQL or Object data source. The errors usually are along the lines of “Could not find xxx that has parameters” along with a list of those parameters. Or an error that states there are too many parameters being passed. Aside from looking for typos, counting or lining up the parameters I will use one of these techniques to try and narrow down what may be the issue. By placing a breakpoint at the i+=1 line and stepping through the loop often times I will see the problem. The code would go in their respective type’s updating method.

VB

SQL Data Source

Dim cmdParams As System.Data.Common.DbParameterCollection = e.Command.Parameters
Dim paramName As String
Dim paramValue As String
Dim i As Integer = 0
While i < cmdParams.Count
   paramName = cmdParams.Item(i).ToString
   paramValue = cmdParams.Item(i).Value.ToString
   i += 1
End While

 

Object Data Source

Dim paramName As String
Dim paramValue As String
Dim i As Integer
While i < e.InputParameters.Count
   paramName = e.InputParameters.Keys(i).ToString
   paramValue = e.InputParameters.Item(i).ToString
   i += 1
End While

 

C#

SQL Data Source

System.Data.Common.DbParameterCollection cmdParams = e.Command.Parameters;
string paramName;
string paramValue;
int i = 0;
while (i < cmdParams.Count) {
    paramName = cmdParams.Item(i).ToString;
    paramValue = cmdParams.Item(i).Value.ToString;
    i += 1;
}

Object Data Source

string paramName;
string paramValue;
int i = 0;
while (i < e.InputParameters.Count) {
    paramName = e.InputParameters.Keys(i).ToString;
    paramValue = e.InputParameters.Item(i).ToString;
    i += 1;
}

 

Technorati Tags: ,,
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Posted On Friday, October 02, 2009 5:47 AM | Feedback (0) |

Powered by: