[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.6

Database Help (250 pts)

Asked by onestar in Programming for ASP.NET

Tags: num_rows, asp, database

Hi, I am totally new to ASP.NET 2.0 using C# and MS SQL 2005. I am coming from a PHP MySQL background. I just started a new job and now I have to do everything in asp. I am having some issues with MSSQL. It just seem very confusing on how to do the database side of things. There just seems many ways of doing things with data readers and data sets and I am not sure what is the best way or the best way to start. Can someone tell me the best way and give me some complete working sample code in C# to get me started. I know this is pretty simple but a little time consuming. I have put up 250 pts.

This is the way I am used to doing things in php and mysql.

I am using a free php class ezsql http://www.jvmultimedia.com/portal/node/6 but this is the jist of it.

// connect to database;
$db = new ezSQL_mysql('db_user','db_password','db_name','db_host');

// get single record (set variable with result)
$userid = $db->get_var("SELECT userid FROM users WHERE userid = 1");
echo "$userid"; // print userid

// get row (return object)
$user = $db->get_row("SELECT * FROM users WHERE userid = 1");
echo "$user->username"; // print username

// get results (return object)
$users = $db->get_results("SELECT * FROM users");
// print out all users
foreach ($users as $myrow)
{
echo "$myrow->username<br />";
}

// execute and insert or update or delete
$sql= "UPDATE `schedule` SET `results` = '$result',`winner` = '$winner' WHERE `game_id` = $game_id LIMIT 1";
$db->query("$sql");

// Class variable that I used all the time as well
$db->num_rows – Number of rows that were returned (by the database) for the last query (if any)
$db->insert_id -- ID generated from the AUTO_INCRIMENT of the previous INSERT operation (if any)
$db->rows_affected -- Number of rows affected (in the database) by the last INSERT, UPDATE or DELETE (if any)

So I need to know how to do all this in ASP.NET 2.0 using C# connecting to MS SQL
I would like full code on how to do this. If you have any good links I should read let me know also.

This is one example I got to work, I am not sure if this is a good way or not.

public void insertUser(string username, string email)
    {
        string con_string = "Data Source=.\\SQLEXPRESS;AttachDbFilename=\"C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Data\\helpdesk.mdf\";Integrated Security=True;Connect Timeout=30;User Instance=True";
        string sql = string.Format(
        "INSERT INTO users (username, email) VALUES ('{0}', '{1}')",username, email);

        SqlCommand cm = new SqlCommand(sql, new SqlConnection(con_string));
        cm.Connection.Open();
        cm.ExecuteNonQuery();
        cm.Connection.Close();
    }

I really appericate any help you can give.

Thanks Onestar
[+][-]01/28/07 12:08 AM, ID: 18413167Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: Programming for ASP.NET
Tags: num_rows, asp, database
Sign Up Now!
Solution Provided By: angelIII
Participating Experts: 2
Solution Grade: A
 
[+][-]01/28/07 08:19 AM, ID: 18414661Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]01/28/07 09:39 AM, ID: 18414905Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01/28/07 11:08 AM, ID: 18415174Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03/25/07 09:22 AM, ID: 18788475Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/12/07 02:57 AM, ID: 18896646Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]04/19/07 07:01 PM, ID: 18943716Administrative Comment

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 30-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92