Connecting To Database in C# (WebApplication)

AshTV

Well-Known Member
Joined
Jun 27, 2011
Messages
357
Reaction score
1
Location
Durban
hi, i would like to know how do you connect to a database to display data in c# web application? i want it to work like this.

if i enter a certain product code, it must display the price. help please.

my web form has the following items:

TextBox1 = to enter Product Code.
TextBox2 = to enter Name.
Button1 = to process the transaction.
label1.Text = to display the output.

my data base that i want to create show have the following fields.

proudctID
price

i would like to know how you connect a database to the c# webapp. tnx
 
First things first.

How do you get data to your application? (server side)

Do you use SQLadapter? Or Entity Framework? Or you have no idea how?
 
Last edited:
Did you try searching Google first before creating a thread? It's really very trivial and programming and Google go very much hand in hand.
 
Did you try searching Google first before creating a thread? It's really very trivial and programming and Google go very much hand in hand.

+1

Very easy to connect to a DB with C#

There should be hundreds of articles on how to do it.
 
there's many, but not what im looking for.

You mean you're too lazy to write the code yourself based on the simple, easy to follow, tutorials online?

Hire someone. I can do it for you. My price is R900 / hour
 
You mean you're too lazy to write the code yourself based on the simple, easy to follow, tutorials online?

Hire someone. I can do it for you. My price is R900 / hour

^^ This.
I'll do it for R850 an hour.

* detects 219 scam *

I only do 119 scams.


Code:
//ensures the SQLconnection will be closed...
using (SqlConnection connection =
           new SqlConnection(connectionString))
{
    SqlCommand command =
        new SqlCommand("select * from MyTable", connection);
    connection.Open();

    SqlDataReader reader = command.ExecuteReader();

    // Reads data
    while (reader.Read())
    {
        Response.Write(String.Format("{0}, {1}",
            reader[0], reader[1]));
    }

    // Close dataReader after use...
    reader.Close();
}

This should work just dandy.
 
after i connect the database, how do i compare the data so that IF the user enters a product number it will display the price from the database?
 
no, i don't know how to do databases. im First Year university, they said must use school knowledge, but i never do IT in school.
 
after i connect the database, how do i compare the data so that IF the user enters a product number it will display the price from the database?

Seriously? Have you tried Googling it? Heck, have you done programming before?
I will just in plain words, answer you....
You need to select the price from the database table where the product number entered matches the product number in the table.

In answer to your above post...
Eish... met ys ja.
You haven't had IT at school, but you've got programming in uni? o0
 
no, i don't know how to do databases. im First Year university, they said must use school knowledge, but i never do IT in school.

I sugest you take your study material and work through it until you understand it even if you manage to jippo this assignment you are not going to make it very far without understanding the basics.
You can see by the harsh replies that this should be fairly straightforward if you have done all the work.
 
I sugest you take your study material and work through it until you understand it even if you manage to jippo this assignment you are not going to make it very far without understanding the basics.
You can see by the harsh replies that this should be fairly straightforward if you have done all the work.

This. If you have zero experience with this then we'd literally have to do it for you to allow you to get it working. I'd start off with a few tutorials and take it from there.

Programming does not work well if you have a working piece of code and have no idea what's going on .
 
Last edited:
Holy balls. Better get your butt in gear if you want to graduate, buddy, this stuff is trivial with literally thousands of resources available online to explain how it works.
 
Top
Sign up to the MyBroadband newsletter
X