Hello all. I am attempting to update one of two database tables using an SqlDataAdapter (getting any changes from my DataSet). I have tested my stproc, and it works fine. Here's the code:

CREATE PROCEDURE [dbo].[procRobUpdate] @db AS NVARCHAR(3), @ID AS NVARCHAR(11), @Panel AS NVARCHAR(3),
@Row AS NVARCHAR(2), @Col AS NVARCHAR(2), @Length AS NVARCHAR(2), @APIFldName AS NVARCHAR(100),
@Updated AS SMALLDATETIME, @Comments AS NVARCHAR(50)
AS


IF @db = 'cur'
BEGIN
UPDATE dbo.tblSources2 SET
Panel = @Panel,
Row = @Row,
Col = @Col,
Length = @Length,
APIFldName= @APIFldName,
Updated = @Updated,
Comments = @Comments
WHERE ID =  @ID
END


ELSE IF @db = 'dev'
BEGIN
UPDATE dbo.tblSourceMods2 SET
Panel = @Panel,
Row = @Row,
Col = @Col,
Length = @Length,
APIFldName= @APIFldName,
Updated = @Updated,
Comments = @Comments
WHERE ID =  @ID
END

Here is the (relevant)code that attempts to do the update:

string debug;
da.Fill(dataSet1); // da is my SqlDataAdapter; dataSet1 is my DataSet
da.UpdateCommand.Parameters.Add("@db", RadioButtonList2.SelectedValue);
TextBox tb;
debug = DataGrid1.DataKeys[e.Item.ItemIndex].ToString();
da.UpdateCommand.Parameters.Add("@ID", DataGrid1.DataKeys
[e.Item.ItemIndex].ToString()); // ID stays the same.
tb = (TextBox)(e.Item.Cells[2].Controls[0]);
debug = debug + " " + tb.Text;
da.UpdateCommand.Parameters.Add("@Panel", tb.Text);
tb = (TextBox)(e.Item.Cells[3].Controls[0]);
debug = debug + " " + tb.Text;
da.UpdateCommand.Parameters.Add("@Row", tb.Text);
tb = (TextBox)(e.Item.Cells[4].Controls[0]);
debug = debug + " " + tb.Text;
da.UpdateCommand.Parameters.Add("@Col", tb.Text);
tb = (TextBox)(e.Item.Cells[5].Controls[0]);
debug = debug + " " + tb.Text;
da.UpdateCommand.Parameters.Add("@Length", tb.Text);
tb = (TextBox)(e.Item.Cells[6].Controls[0]);
debug = debug + " " + tb.Text;
da.UpdateCommand.Parameters.Add("@APIFldName", tb.Text);
dt = DateTime.Now;
debug = debug + " " + dt.ToString();
da.UpdateCommand.Parameters.Add("@Updated", dt);
tb = (TextBox)(e.Item.Cells[8].Controls[0]);
debug = debug + " " + tb.Text;
da.UpdateCommand.Parameters.Add("@Comments", tb.Text);


string s;
if(RadioButtonList2.SelectedValue.Equals("cur")) // which table?
{
s = "tblSources2";
}
else
{
s = "tblSourceMods2";
}


debug = s + " " + debug;
int rows = da.Update(dataSet1, s);
Label1.Text = debug + " # of rows affected: " + rows.ToString();
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();

"debug" looks like it should; all of the parameters are correct. "rows" is always zero, which is strange as that should throw a concurrency error if nothing was updated, shouldn't it? I'm lost. Any help would be great. Thanks for your time.

Could this be a problem w/ DataBinding/DataMember settings in DataGrid1? Since I'm switching table, maybe they should be manipulated as well?

...or is there something else that needs to happen in this section of the code:

da.Update(dataSet1, s);
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();

Thanks in advance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.