This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C470C1.0AB15790
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am pulling my hair out over this one. I have done this same kind of =
thing in VB.Net but in C# it doesn't work. I dont' receive any errors =
either, it just won't update the pubs.Authors table. Here is the code:

private void CodedDataGrid_Load(object sender, System.EventArgs e)
{
//create a new connection object
String ConnectString =3D "Server=3D" + "MyMachine" + "; " + "User ID=3D" =
+ "sa" + "; Password=3D" + "password" + "; initial catalog =3D " + =
"pubs" + ";";
conn =3D new SqlConnection(ConnectString); //create a new adapter
adp =3D new SqlDataAdapter("Select au_id,au_lname,au_fname,contract FROM =
authors",conn);

//creat ea new dataset
ds =3D new DataSet();
adp.Fill(ds);
this.dbGrid.DataSource =3D ds;

}

private void btnNew_Click(object sender, System.EventArgs e)
{
AdapterInsert();

=20
//add a new record to the dataset, but first

try
{
adp.Update(ds,"Table");
}
catch (System.Data.SqlClient.SqlException sqlEx)
{
MessageBox.Show(sqlEx.Message);
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}

}
private void AdapterInsert()
{
insComm =3D new SqlCommand();
adp.InsertCommand =3D insComm;
adp.InsertCommand.Connection =3D conn;

adp.InsertCommand.CommandType =3D=20

CommandType.StoredProcedure;
adp.InsertCommand.CommandText =3D "InsertAuthor";

SqlParameter MySqlParam1 =3D new =
SqlParameter("@au_id",SqlDbType.VarChar);
MySqlParam1.Value =3D this.txtID.Text;
MySqlParam1.SourceColumn =3D "au_id";
adp.InsertCommand.Parameters.Add(MySqlParam1);

SqlParameter MySqlParam2 =3D new =
SqlParameter("@au_fname",SqlDbType.VarChar);
MySqlParam2.Value =3D this.txtFName.Text;
MySqlParam2.SourceColumn =3D "au_fname";
adp.InsertCommand.Parameters.Add(MySqlParam2);

SqlParameter MySqlParam3 =3D new =
SqlParameter("@au_lname",SqlDbType.VarChar);
MySqlParam3.Value =3D this.txtLName.Text;
MySqlParam3.SourceColumn =3D "au_lname";
adp.InsertCommand.Parameters.Add(MySqlParam3);

SqlParameter MySqlParam4 =3D new =
SqlParameter("@contract",SqlDbType.Bit);
MySqlParam4.Value =3D "1";
MySqlParam4.SourceColumn =3D "contract";
adp.InsertCommand.Parameters.Add(MySqlParam4);

}

What the heck am I missing here?

Thanks.





=20

------=_NextPart_000_000A_01C470C1.0AB15790
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2162" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>I am pulling my hair out over this one. =
I have done=20
this same kind of thing in VB.Net but in C# it doesn't work. I dont' =
receive any=20
errors either, it just won't update the pubs.Authors table. Here is the=20
code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>private void CodedDataGrid_Load(object =
sender,=20
System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;//create a new =
connection=20
object<BR></FONT><FONT face=3DArial size=3D2>String ConnectString =3D =
"Server=3D" +=20
"MyMachine" + "; " + </FONT><FONT face=3DArial size=3D2>"User ID=3D" + =
"sa" + ";=20
Password=3D" + "password" + </FONT><FONT face=3DArial size=3D2>"; =
initial catalog =3D "=20
+ "pubs" + ";";<BR></FONT><FONT face=3DArial size=3D2>conn =3D new=20
SqlConnection(ConnectString);</FONT><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;//create a new adapter<BR>adp =3D new=20
SqlDataAdapter("Select </FONT><FONT face=3DArial=20
size=3D2>au_id,au_lname,au_fname,contract FROM =
authors",conn);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;//creat ea new=20
dataset<BR>&nbsp;&nbsp;&nbsp;ds =3D new=20
DataSet();<BR>&nbsp;&nbsp;&nbsp;adp.Fill(ds);<BR>&nbsp;&nbsp;&nbsp;this.d=
bGrid.DataSource=20
=3D ds;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;private void =
btnNew_Click(object=20
sender, System.EventArgs=20
e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;AdapterInsert();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//add a new=20
record to the dataset, but first</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbs=
p;&nbsp;adp.Update(ds,"Table");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nb=
sp;catch=20
(System.Data.SqlClient.SqlException=20
sqlEx)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(=
sqlEx.Message);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(System.=
Exception=20
ex)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(ex.=
Message);<BR>&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private =
void=20
AdapterInsert()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;insComm =3D new=20
SqlCommand();<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand =3D=20
insComm;<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Connection =3D =
conn;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;adp.InsertCommand.CommandType =3D=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>CommandType.StoredProcedure;<BR>&nbsp;&nbsp;&nbsp;adp.InsertComm=
and.CommandText=20
=3D "InsertAuthor";</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam1 =3D new=20
</FONT><FONT face=3DArial=20
size=3D2>SqlParameter("@au_id",SqlDbType.VarChar);<BR>&nbsp;&nbsp;&nbsp;M=
ySqlParam1.Value=20
=3D this.txtID.Text;<BR>&nbsp;&nbsp;&nbsp;MySqlParam1.SourceColumn =3D=20
"au_id";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlParam=
1);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam2 =3D new=20
</FONT><FONT face=3DArial=20
size=3D2>SqlParameter("@au_fname",SqlDbType.VarChar);<BR>&nbsp;&nbsp;&nbs=
p;MySqlParam2.Value=20
=3D this.txtFName.Text;<BR>&nbsp;&nbsp;&nbsp;MySqlParam2.SourceColumn =
=3D=20
"au_fname";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlPa=
ram2);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam3 =3D new=20
</FONT><FONT face=3DArial=20
size=3D2>SqlParameter("@au_lname",SqlDbType.VarChar);<BR>&nbsp;&nbsp;&nbs=
p;MySqlParam3.Value=20
=3D this.txtLName.Text;<BR>&nbsp;&nbsp;&nbsp;MySqlParam3.SourceColumn =
=3D=20
"au_lname";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlPa=
ram3);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam4 =3D new=20
</FONT><FONT face=3DArial=20
size=3D2>SqlParameter("@contract",SqlDbType.Bit);<BR>&nbsp;&nbsp;&nbsp;My=
SqlParam4.Value=20
=3D "1";<BR>&nbsp;&nbsp;&nbsp;MySqlParam4.SourceColumn =3D=20
"contract";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlPa=
ram4);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>}<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>What the heck am I missing =
here?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_000A_01C470C1.0AB15790--

Re: Help with SqlDataAdapter Update command (C#) by Norton

Norton
Fri Jul 23 16:04:17 CDT 2004

This is a multi-part message in MIME format.

------=_NextPart_000_0008_01C470D7.1836F170
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Well, apparently I had forgotten all the automagical stuff that a data =
adapter does for me. Not only were my parameter source columns =
incorrectly named, but I also did not add the row to the dataset table.

Geez!

Norton
"Norton" <thenortonz@hotmail.com> wrote in message =
news:%23%23bWQKOcEHA.996@TK2MSFTNGP12.phx.gbl...
I am pulling my hair out over this one. I have done this same kind of =
thing in VB.Net but in C# it doesn't work. I dont' receive any errors =
either, it just won't update the pubs.Authors table. Here is the code:

private void CodedDataGrid_Load(object sender, System.EventArgs e)
{
//create a new connection object
String ConnectString =3D "Server=3D" + "MyMachine" + "; " + "User =
ID=3D" + "sa" + "; Password=3D" + "password" + "; initial catalog =3D " =
+ "pubs" + ";";
conn =3D new SqlConnection(ConnectString); //create a new adapter
adp =3D new SqlDataAdapter("Select au_id,au_lname,au_fname,contract =
FROM authors",conn);

//creat ea new dataset
ds =3D new DataSet();
adp.Fill(ds);
this.dbGrid.DataSource =3D ds;

}

private void btnNew_Click(object sender, System.EventArgs e)
{
AdapterInsert();

=20
//add a new record to the dataset, but first

try
{
adp.Update(ds,"Table");
}
catch (System.Data.SqlClient.SqlException sqlEx)
{
MessageBox.Show(sqlEx.Message);
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}

}
private void AdapterInsert()
{
insComm =3D new SqlCommand();
adp.InsertCommand =3D insComm;
adp.InsertCommand.Connection =3D conn;

adp.InsertCommand.CommandType =3D=20

CommandType.StoredProcedure;
adp.InsertCommand.CommandText =3D "InsertAuthor";

SqlParameter MySqlParam1 =3D new =
SqlParameter("@au_id",SqlDbType.VarChar);
MySqlParam1.Value =3D this.txtID.Text;
MySqlParam1.SourceColumn =3D "au_id";
adp.InsertCommand.Parameters.Add(MySqlParam1);

SqlParameter MySqlParam2 =3D new =
SqlParameter("@au_fname",SqlDbType.VarChar);
MySqlParam2.Value =3D this.txtFName.Text;
MySqlParam2.SourceColumn =3D "au_fname";
adp.InsertCommand.Parameters.Add(MySqlParam2);

SqlParameter MySqlParam3 =3D new =
SqlParameter("@au_lname",SqlDbType.VarChar);
MySqlParam3.Value =3D this.txtLName.Text;
MySqlParam3.SourceColumn =3D "au_lname";
adp.InsertCommand.Parameters.Add(MySqlParam3);

SqlParameter MySqlParam4 =3D new =
SqlParameter("@contract",SqlDbType.Bit);
MySqlParam4.Value =3D "1";
MySqlParam4.SourceColumn =3D "contract";
adp.InsertCommand.Parameters.Add(MySqlParam4);

}

What the heck am I missing here?

Thanks.





=20

------=_NextPart_000_0008_01C470D7.1836F170
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2900.2162" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Well, apparently I had forgotten all =
the=20
automagical stuff that a data adapter does for me. Not only were my =
parameter=20
source columns incorrectly named, but I also did not add the row to the =
dataset=20
table.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Geez!</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Norton</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Norton" &lt;<A=20
href=3D"mailto:thenortonz@hotmail.com">thenortonz@hotmail.com</A>&gt; =
wrote in=20
message <A=20
=
href=3D"news:%23%23bWQKOcEHA.996@TK2MSFTNGP12.phx.gbl">news:%23%23bWQKOcE=
HA.996@TK2MSFTNGP12.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>I am pulling my hair out over this =
one. I have=20
done this same kind of thing in VB.Net but in C# it doesn't work. I =
dont'=20
receive any errors either, it just won't update the pubs.Authors =
table. Here=20
is the code:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>private void =
CodedDataGrid_Load(object sender,=20
System.EventArgs e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;//create a new =
connection=20
object<BR></FONT><FONT face=3DArial size=3D2>String ConnectString =3D =
"Server=3D" +=20
"MyMachine" + "; " + </FONT><FONT face=3DArial size=3D2>"User ID=3D" + =
"sa" + ";=20
Password=3D" + "password" + </FONT><FONT face=3DArial size=3D2>"; =
initial catalog =3D=20
" + "pubs" + ";";<BR></FONT><FONT face=3DArial size=3D2>conn =3D new=20
SqlConnection(ConnectString);</FONT><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;//create a new adapter<BR>adp =3D new=20
SqlDataAdapter("Select </FONT><FONT face=3DArial=20
size=3D2>au_id,au_lname,au_fname,contract FROM =
authors",conn);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;//creat ea new=20
dataset<BR>&nbsp;&nbsp;&nbsp;ds =3D new=20
=
DataSet();<BR>&nbsp;&nbsp;&nbsp;adp.Fill(ds);<BR>&nbsp;&nbsp;&nbsp;this.d=
bGrid.DataSource=20
=3D ds;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;private void =
btnNew_Click(object=20
sender, System.EventArgs=20
e)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;AdapterInsert();</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp;//add a=20
new record to the dataset, but first</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
=
size=3D2>&nbsp;&nbsp;&nbsp;try<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbs=
p;&nbsp;adp.Update(ds,"Table");<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nb=
sp;catch=20
(System.Data.SqlClient.SqlException=20
=
sqlEx)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(=
sqlEx.Message);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;catch(System.=
Exception=20
=
ex)<BR>&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox.Show(ex.=
Message);<BR>&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;private =
void=20
AdapterInsert()<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;insComm =3D new=20
SqlCommand();<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand =3D=20
insComm;<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Connection =3D=20
conn;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;adp.InsertCommand.CommandType =3D=20
</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
=
size=3D2>CommandType.StoredProcedure;<BR>&nbsp;&nbsp;&nbsp;adp.InsertComm=
and.CommandText=20
=3D "InsertAuthor";</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam1 =3D new=20
</FONT><FONT face=3DArial=20
=
size=3D2>SqlParameter("@au_id",SqlDbType.VarChar);<BR>&nbsp;&nbsp;&nbsp;M=
ySqlParam1.Value=20
=3D this.txtID.Text;<BR>&nbsp;&nbsp;&nbsp;MySqlParam1.SourceColumn =3D =

=
"au_id";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlParam=
1);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam2 =3D new=20
</FONT><FONT face=3DArial=20
=
size=3D2>SqlParameter("@au_fname",SqlDbType.VarChar);<BR>&nbsp;&nbsp;&nbs=
p;MySqlParam2.Value=20
=3D this.txtFName.Text;<BR>&nbsp;&nbsp;&nbsp;MySqlParam2.SourceColumn =
=3D=20
=
"au_fname";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlPa=
ram2);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam3 =3D new=20
</FONT><FONT face=3DArial=20
=
size=3D2>SqlParameter("@au_lname",SqlDbType.VarChar);<BR>&nbsp;&nbsp;&nbs=
p;MySqlParam3.Value=20
=3D this.txtLName.Text;<BR>&nbsp;&nbsp;&nbsp;MySqlParam3.SourceColumn =
=3D=20
=
"au_lname";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlPa=
ram3);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp;SqlParameter =
MySqlParam4 =3D new=20
</FONT><FONT face=3DArial=20
=
size=3D2>SqlParameter("@contract",SqlDbType.Bit);<BR>&nbsp;&nbsp;&nbsp;My=
SqlParam4.Value=20
=3D "1";<BR>&nbsp;&nbsp;&nbsp;MySqlParam4.SourceColumn =3D=20
=
"contract";<BR>&nbsp;&nbsp;&nbsp;adp.InsertCommand.Parameters.Add(MySqlPa=
ram4);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>}<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>What the heck am I missing =
here?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thanks.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial =
size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0008_01C470D7.1836F170--


Re: Help with SqlDataAdapter Update command (C#) by William

William
Sat Jul 24 21:46:35 CDT 2004

Norton:

For future reference, there's a few things you can try that may help you
out. If your dataset doesn't have changes, calling update all year won't do
anything. http://www.knowdotnet.com/articles/efficient_pt4.html (this
should help a bit). Anyway, one thing helpful in a development/test/debug
scenario is inserting an assertion right before you call update :

Debug.Assert(whateverDataSet.HasChanges, "No Changes Present - Update Won't
Do Anything");

Checking for HasChanges in production is useless b/c calling haschanges
loops through the dataset anyway checking for changed rowstates, and that's
what Update does as well - the only difference is update fires updates if
there are any - but if there aren;'t the net effect is the same. However in
Test it's good to know right off the bat that an update that you expect to
work isn't in fact working. If it has changes as you expect then nothing
will be any different, if it doesn't, then the asssertion will fail and a
big ugly box will pop up telling you so (but will allow you to continue
break etc). For that reason I use Debug.Assert(false,
exceptionName.ToString()); in my try/catch blocks too b/c I can stop the app
from there without clicking Ok in a message box and then closing the app or
I can continue. Also, I don't have to worry about removing the code for
release builds - it won't execute if Debug is defined so that's also a
convenience.

The nice thing about checking this way is that you'll know immediately and
won't have to physically examine the db only to find it's not updated
(besides, you might miss it when you check the db - and if you want you can
still do both).

Another thing that's often a helpful tool is writing code for the
RowUpdating event - as a general habit, I'll do this so I can show the user
some progress while the db is updating and it has the side effect of helping
me verify that something happened (I also run my data access stuff in a
separate thread - if you do so as well, be careful of the standard thread
related issues when giving the user some feedback, dont' want to create
other problems for yourself).

Another thing that's a good idea is reconfiguring your dataadapters
periodically unlless you are positive that none of the field names or
anything have changed. This can cause some problem too particularly ifyou
use SELECT * and add additional colulmns.

Bill Vaughn has an excellent article on www.betav.com -> Articles -> MSDN
titled Weaning Developers from the CommandBuilder that will probably
convince you to roll your own logic in most instances. This elminates the
problems associated with AutoMagic code generation of your logic - it's a
mixed blessing b/c while it saves you some time, it also puts some distance
between you and your code and unless you have a firm understanding of what
it does for you (the configuration wizard), it can inhibit learning (or help
you forget) and make it a little more difficult to debug (the constructors
it uses are so verbose that it's very difficult to read at times).

Anyway, I know the stuff I recommended helped me along the way (As did
Bill's ADO.NET Best practices book and David Sceppa's ADO.NET Core
Reference) and I figured I'd mention it.

Cheers,

Bill

--
W.G. Ryan MVP Windows - Embedded

Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
"Norton" <thenortonz@hotmail.com> wrote in message
news:%23oKVhiPcEHA.3904@TK2MSFTNGP12.phx.gbl...
Well, apparently I had forgotten all the automagical stuff that a data
adapter does for me. Not only were my parameter source columns incorrectly
named, but I also did not add the row to the dataset table.

Geez!

Norton
"Norton" <thenortonz@hotmail.com> wrote in message
news:%23%23bWQKOcEHA.996@TK2MSFTNGP12.phx.gbl...
I am pulling my hair out over this one. I have done this same kind of
thing in VB.Net but in C# it doesn't work. I dont' receive any errors
either, it just won't update the pubs.Authors table. Here is the code:

private void CodedDataGrid_Load(object sender, System.EventArgs e)
{
//create a new connection object
String ConnectString = "Server=" + "MyMachine" + "; " + "User ID=" + "sa"
+ "; Password=" + "password" + "; initial catalog = " + "pubs" + ";";
conn = new SqlConnection(ConnectString); //create a new adapter
adp = new SqlDataAdapter("Select au_id,au_lname,au_fname,contract FROM
authors",conn);

//creat ea new dataset
ds = new DataSet();
adp.Fill(ds);
this.dbGrid.DataSource = ds;

}

private void btnNew_Click(object sender, System.EventArgs e)
{
AdapterInsert();


//add a new record to the dataset, but first

try
{
adp.Update(ds,"Table");
}
catch (System.Data.SqlClient.SqlException sqlEx)
{
MessageBox.Show(sqlEx.Message);
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}

}
private void AdapterInsert()
{
insComm = new SqlCommand();
adp.InsertCommand = insComm;
adp.InsertCommand.Connection = conn;

adp.InsertCommand.CommandType =

CommandType.StoredProcedure;
adp.InsertCommand.CommandText = "InsertAuthor";

SqlParameter MySqlParam1 = new
SqlParameter("@au_id",SqlDbType.VarChar);
MySqlParam1.Value = this.txtID.Text;
MySqlParam1.SourceColumn = "au_id";
adp.InsertCommand.Parameters.Add(MySqlParam1);

SqlParameter MySqlParam2 = new
SqlParameter("@au_fname",SqlDbType.VarChar);
MySqlParam2.Value = this.txtFName.Text;
MySqlParam2.SourceColumn = "au_fname";
adp.InsertCommand.Parameters.Add(MySqlParam2);

SqlParameter MySqlParam3 = new
SqlParameter("@au_lname",SqlDbType.VarChar);
MySqlParam3.Value = this.txtLName.Text;
MySqlParam3.SourceColumn = "au_lname";
adp.InsertCommand.Parameters.Add(MySqlParam3);

SqlParameter MySqlParam4 = new SqlParameter("@contract",SqlDbType.Bit);
MySqlParam4.Value = "1";
MySqlParam4.SourceColumn = "contract";
adp.InsertCommand.Parameters.Add(MySqlParam4);

}

What the heck am I missing here?

Thanks.