Hi,

I am just start programming by using C# not longer time,there are few thing i don't understand.

1) I have a task that need me to access to the database in the server. Can i know what coding what i should use in the C# webform for me to access the database in the server. Below are my coding. However, it doesn't work!

try
            {
                SqlConnection conn = new SqlConnection();
                conn.ConnectionString =new conn();
                Data Source=\\Server ;uid=User;pwd=password;database=Database1;
                
                
                /*
                //get the connection string from app.config
                string connectionString = ConfigurationManager.AppSettings["SqlDBConn"];
                //create a new connection and assign our connection string
                SqlConnection sqlConnection = new SqlConnection(connectionString);
                //http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=127609&SiteID=1
                //create a new command and pass our sql statement and our connection object.
                SqlCommand sqlCommand = new SqlCommand(strCriteria.ToString(), sqlConnection);
                */
                //open the connection
                sqlConnection.Open();

                //create a new sqladapter and set its command object with our sqlcommand
                SqlDataAdapter sqlAdapter = new SqlDataAdapter(sqlCommand);

                //fill the dataset with the result of our query from the specified command
                sqlAdapter.Fill(dsList);
            }

2) And i also not so understand about the coding by

Using xxxx.dll

because i was told that i need to use the file inside the Bin folder for me to run the application.
Thanks a lot.

Regard,
Jim
Thanks from bottom of my heart. ^^

Whats actually in your connection string?

What are you trying to do here:

SqlConnection conn = new SqlConnection();

Here is an example for you: SQL connection example

Hi all,

I am trying to use C# to create a webform, Use it to access database in another server, then i need to display the table in the datagrid, able to select the data by add, edit and delete. Thanks.

Ok, so you ignored my question - whats in your connection details?

ConfigurationManager.AppSettings["SqlDBConn"];
                //create a new connection and assign our connection string
                SqlConnection sqlConnection = new SqlConnection(connectionString);

When you debug this, what does it show?

oops ... sorry wrong line. What are you trying to do here:

conn.ConnectionString = new conn();

Hi LizR,

I actually also not sure what coding am i refer to. But as i understand, is it i should create
i) connection string
ii) sqlconnection
iii) sqlcommand
iv) sqlConnection.Open
v) sqlDataAdapter
vi) sqlDataAdapter.Fill(datagrid)

this is the basic uderstanding of the accessing method. Am i doing the correct thing or in a lost way?

here is something, that will throw light on that problem: SqlConnection.ConnectionString Property

and in that string:

conn.ConnectionString = new conn();

you're trying to assign ConnectionString property by creating new instance of the instance of the class SqlConnection.

Antenka points a good point.. You're trying to assign a new connection to a string, Im surprised that would compile.

Your flow of what you need todo is right, you just get a bit jumbled along the way of doing it I think.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.