Solved

DataTable Fill

Posted on 2014-04-15
3
200 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
install app on other machine 13 32
New to SOAP and need some direction 10 40
Authentication of Web Services 3 46
Vb.net dynamic formulas in runtime 11 61
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

947 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now