•
•
•
•
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
![]() |
•
•
Join Date: Jun 2005
Posts: 5
Reputation:
Rep Power: 0
Solved Threads: 0
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.
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.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
- Updating drivers (Windows NT / 2000 / XP / 2003)
- HELP! Updating Sound Card Driver and now Windows Only boots up Black Screen! :( (Windows NT / 2000 / XP / 2003)
- ASP.Net VB Page to update a users profile not updating. (MS SQL)
- Re: Problem in updating project for Microsoft Project 2002 and 2003 (Windows Software)
- IE slow after updating Norton Virus Defs (Web Browsers)
- updating 2 HTML tables on one PHP page (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: WriteLine Specifyng what line to write in a textfile
- Next Thread: DataGrid read-only columns


Linear Mode