Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Using SqlDataAdapter

Reply
Thread Tools

Using SqlDataAdapter

 
 
RN1
Guest
Posts: n/a
 
      03-17-2008
When using the SqlCommand object, records can be inserted/updated/
deleted in the underlying data source (i.e. the SQL Server database
table) directly by using code like this:

--------------------------------------------------------------------------------
Dim strSQL As String
Dim sqlCmd As SqlCommand
Dim sqlConn As SqlConnection
strSQL = "INSERT INTO MyTable (Col1, Col2) VALUES........."
sqlConn = New SqlConnection("........")
sqlCmd = New SqlCommand(strSQL, sqlConn)

sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
--------------------------------------------------------------------------------

But if the SqlDataAdapter object is used to insert/update/delete
records in the data source, is it ALWAYS necessary to first make the
necessary changes in the DataSet for the data source to reflect the
changes?
 
Reply With Quote
 
 
 
 
Manish
Guest
Posts: n/a
 
      03-17-2008
Does your SqlDataAdapter have the required SqlCommands it needs (e.g.,
select, insert, update, delete)?

if yes then you can update using code below:

StringBuilder sb = new StringBuilder("");
sb.Append("UPDATE Categories SET ");
sb.Append("CategoryName=@sCategoryName WHERE CategoryID=@nCategoryID");
SqlConnection conn = this.getConnectionString();
SqlCommand cmd = new SqlCommand(sb.ToString(), conn);
SqlParameter p1 = new SqlParameter("@sCategoryName", SqlDbType.VarChar, 30);
p1.Direction = ParameterDirection.Input;
p1.Value = ((TextBox)(e.Item.Cells[1].Controls[0])).Text;
cmd.Parameters.Add(p1);

SqlParameter p2 = new SqlParameter("@nCategoryID", SqlDbType.Int);
p2.Direction = ParameterDirection.Input;
p2.Value = C1WebGrid1.DataKeys[e.Item.ItemIndex];
cmd.Parameters.Add(p2);

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();

Regards,
Manish
www.ComponentOne.com


"RN1" wrote:

> When using the SqlCommand object, records can be inserted/updated/
> deleted in the underlying data source (i.e. the SQL Server database
> table) directly by using code like this:
>
> --------------------------------------------------------------------------------
> Dim strSQL As String
> Dim sqlCmd As SqlCommand
> Dim sqlConn As SqlConnection
> strSQL = "INSERT INTO MyTable (Col1, Col2) VALUES........."
> sqlConn = New SqlConnection("........")
> sqlCmd = New SqlCommand(strSQL, sqlConn)
>
> sqlConn.Open()
> sqlCmd.ExecuteNonQuery()
> sqlConn.Close()
> --------------------------------------------------------------------------------
>
> But if the SqlDataAdapter object is used to insert/update/delete
> records in the data source, is it ALWAYS necessary to first make the
> necessary changes in the DataSet for the data source to reflect the
> changes?
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using sqlDataAdapter to fill Dataset Andy G ASP .Net Datagrid Control 1 01-31-2005 10:12 PM
Wht is the advantage of using SqlDataAdapter Ashish ASP .Net 3 09-07-2004 04:01 PM
"Login failed for user 'sa'" datagrid control - SqlDataAdapter Jerry Higgins ASP .Net 6 04-21-2004 03:51 PM
TimeOut on SqlDataAdapter.Fill Dan ASP .Net 1 04-02-2004 11:05 PM
How to update the Database by using SqlDataAdapter object in asp.net? zhaoJian ASP .Net 0 11-06-2003 03:06 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57