Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

DataTable Fill

Posted on 2014-04-15
3
Medium Priority
?
210 Views
Last Modified: 2014-04-20
was wondering if my explanation bellow is correct
string SQL = @" insert into User_Activity_Log
            values('" + UserName + "', '" + UserID + "' ,getdate(), '" + action + "' ,'','" + IP + "')";
  SqlConnection con = Main.GetDBConnection();
// Create a connection to SQL Database with intance con

            DataTable consultantTable = new DataTable();
//Create a table in memory called consultantTable

            SqlDataAdapter Consultantdataadapter = new SqlDataAdapter(SQL, con);
            Consultantdataadapter.Fill(consultantTable);
//Fill the consultantTable with the SQL querry in memory....  Does that mean it actually populate the database?
0
Comment
Question by:yguyon28
3 Comments
 
LVL 16

Accepted Solution

by:
Wasim Akram Shaik earned 1500 total points
ID: 40002055
I don't think so.. as you are not doing any activity at database end, apart from just logging in a user activity table..

you must be doing some other thing.. like loading of some other database table with configuration values in memory, so that object gets referred else where in the execution of the program further..
0
 
LVL 22

Expert Comment

by:plusone3055
ID: 40002071
no and also you have no commande parameters adding any value to the table

for example

cmd.Parameters.Add("@username", System.Data.SqlDbType.NVarChar).Value = username.Text;


additionally your not executing the query
cmd.ExecuteNonQuery();
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40002267
I imagine the code you have will simply throw an exception if you tried to run it.

The DataTable Fill() method populates the DataTable from the database using a SELECT statement. An INSERT statement would suggest a push to the database, whereas the Fill() method is used to pull from the database.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question