|
-
May 28th, 2003, 10:51 AM
#1
Thread Starter
Lively Member
Reason behind a command object and data adapter commands
What is the purpose of creating a command object if you can create the sql statements directly from the data adpater wizard?
And the data adapter will generate Select, Update, Insert and Delete commands automatically. This would require 4 command objects?
I have been learning ASP.Net through the GUI objects and tool bars. Maybe this would seem more clear when writing all the code myself.
any other insight on the topic would be appreciated. Thank you,
Jason Meckley
Database Analyst
WITF
-
May 28th, 2003, 10:48 PM
#2
PowerPoster
I don't use dataAdapters at all in my code normally. This is because I usually am calling stored proceedures that insert, update, retrieve, and delete my data. For this reason, the Command object is really needed. If you are strictly working with the data that is only modified through SQL statements, I guess it would work just fine.
-
May 28th, 2003, 10:51 PM
#3
PowerPoster
Just to add a note, the DataAdapter is created to make your life easier as a programmer. You don't need to write much db code if you are not doing anything out of the ordinary and using databound controls. That is what is so cool about it. Use it as much as you can, but if you face problems that require more than what the DataAdapter provides, remember that the Command object is out there.
-
May 29th, 2003, 07:11 AM
#4
Thread Starter
Lively Member
So it I want to execute commands directly against the database I can skip the data adapter all together and use a command object to execute the query?
what if I have a set of records I want to bind to a control, wouldn't I need a data adapter to fill a data set to bind to the control? I did not think it was possible to execute a command object and bind the data to a control without a data adapter or data set.
Jason Meckley
Database Analyst
WITF
-
May 29th, 2003, 07:32 AM
#5
Frenzied Member
If you are using a DataSet, you will have to use a DataAdapter to fill it. Now if this is a web project like I think it is, then you will want the best possible performance. This is where the DataReader comes in. Its a forward only reader, and its very fast. You can also bind to it (you cant bind to in a WinForms project).
what if I have a set of records I want to bind to a control, wouldn't I need a data adapter to fill a data set to bind to the control? I did not think it was possible to execute a command object and bind the data to a control without a data adapter or data set.
If all you are doing is showing a data, this is how its done
PHP Code:
string connString = "connection here";
SqlConnection sqlConn = new SqlConnection(connString);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Select * From MyTable";
cmd.Connection = connString;
SqlDataReader reader = cmd.ExecuteReader();
dataGrid1.DataSource = reader;
dataGrid1.DataBind();
sqlConn.Close();
-
May 29th, 2003, 08:16 AM
#6
Thread Starter
Lively Member
DevGrp
Thanx for the code! I had to translate it into VB and figure out some of the namespaces, but I got it. This is much faster on the processing time.
Now I need to figure out how to modify the columns and links and sorts within the grid and I should have what I need for controling grids.
Jason Meckley
Database Analyst
WITF
-
May 29th, 2003, 10:40 AM
#7
PowerPoster
A great book is the ASP.NET Data Web Controls Kick Start book from Sams publishing. It is small, to the point, and full of good information.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|