I am new Programmer. In my Comp. I am the Only Programmer. So I have many Questions in my Mind.
In my Project i am using Below Code For add.
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select * from " + datatable + " where code='" + textBox1.Text + "'";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
already = 1;
}
connection.Close();
Is this Correct Way. Or DAL, Stored Procedure, 3 tire Architure Which is most effective. And What standard Code is maintain in Companies.
I am doing Project and Got Solutions Also. But I don’t know this way is Correct or Not.
I think Most of you understand my problem?.
Thanks in Advance….
To ensure that connections are always closed, open the connection inside of a using block. as shown in the following code fragment. Doing so ensures that the connection is automatically closed when the code exits the block.
This is a part of Connection Pooling. And it is one of the good way of doing Sql connection.