User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 391,590 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,663 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 6335 | Replies: 2
Reply
Join Date: Jun 2005
Posts: 5
Reputation: cob027 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cob027 cob027 is offline Offline
Newbie Poster

Updating DB using SqlDataAdapter

  #1  
Jun 7th, 2005
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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Posts: 5
Reputation: cob027 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cob027 cob027 is offline Offline
Newbie Poster

Re: Updating DB using SqlDataAdapter

  #2  
Jun 8th, 2005
Could this be a problem w/ DataBinding/DataMember settings in DataGrid1? Since I'm switching table, maybe they should be manipulated as well?
Reply With Quote  
Join Date: Jun 2005
Posts: 5
Reputation: cob027 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
cob027 cob027 is offline Offline
Newbie Poster

Re: Updating DB using SqlDataAdapter

  #3  
Jun 8th, 2005
...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.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb ASP.NET Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the ASP.NET Forum

All times are GMT -4. The time now is 11:13 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC