I have a wierd problem. I have made a copy/paste from one of my programs that finns a datagrid with values from a sql db. And it works fine in that example, but when I use the same code with the oledb and an access db I get an error... here is the code for the updatecommand
The error occurs on the line
and the error is:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
The only thing I can think of is that primary keys are different in Access and SQL... other than that there is no difference between the code...
The stored procedure looks like:
UPDATE reportusers SET username = [@pusername], [password] = [@ppassword], admin = [@padmin]
WHERE userid=[@puserid];
any help would be nice! This is a wierd problem...
kind regards
Henrik
[edit]changed PHP tags for VB tags [/edit]
Code:
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
OleDbConnection myConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\inetpub\wwwroot\webreport\userdb.mdb");
OleDbCommand cmd = new OleDbCommand("Update",myConn);
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter param = new OleDbParameter();
string userid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
param = cmd.Parameters.Add("@puserid",OleDbType.varchar);
param.Direction = ParameterDirection.Input;
param.Value = userid;
string username = ((TextBox)e.Item.Cells[1].Controls[0]).Text;
param = cmd.Parameters.Add("@pusername",OleDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Value = username;
string password = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
param = cmd.Parameters.Add("@ppassword",OleDbType.VarChar);
param.Direction = ParameterDirection.Input;
param.Value = password;
string admin = ((TextBox)e.Item.Cells[3].Controls[0]).Text;
param = cmd.Parameters.Add("@padmin",OleDbType.Boolean);
param.Direction = ParameterDirection.Input;
param.Value = System.Convert.ToBoolean(admin);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
DataGrid1.EditItemIndex = -1;
BindGrid();
}
The error occurs on the line
Code:
string userid = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
and the error is:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
The only thing I can think of is that primary keys are different in Access and SQL... other than that there is no difference between the code...
The stored procedure looks like:
UPDATE reportusers SET username = [@pusername], [password] = [@ppassword], admin = [@padmin]
WHERE userid=[@puserid];
any help would be nice! This is a wierd problem...
kind regards
Henrik
[edit]changed PHP tags for VB tags [/edit]
Last edited by a moderator: