Solved

DataTable Fill

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

12 Experts available now in Live!

Get 1:1 Help Now