Skip to content

sql Connection

September 21, 2013

private SqlConnection conn = new SqlConnection();
private SqlCommand comm = new SqlCommand();
private SqlDataAdapter adp = new SqlDataAdapter();
DataTable dt = new DataTable();

protected void Page_Load(object sender, EventArgs e)
{
conn = new SqlConnection(“Data Source=WAQAS-PC;Initial Catalog=waqasDbTest;Integrated Security=True”);
loadData();
}

private void loadData()
{
dt.Clear();
string sqlQuery = string.Empty;
sqlQuery = “select User_ID AS ID , User_Name as Name , User_Password as Password from wDbTest Order by USer_id ASC”;
conn.Open();
adp = new SqlDataAdapter(sqlQuery, conn);
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
conn.Close();       }

protected void selectStoredProcedure(string spName, Hashtable param, DataTable tblName)
{
dt.Clear();
conn.Open();
comm.Parameters.Clear();
comm.Connection = conn;
comm.CommandText = spName;
comm.CommandType = CommandType.StoredProcedure;
foreach (string para in param.Keys)
{
comm.Parameters.AddWithValue(para, param[para]);
}
adp.SelectCommand = (comm);
adp.Fill(tblName);
conn.Close();   }

 

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Panel1.Visible = true;
Label4.Text = “”;
txtID.Text = GridView1.SelectedRow.Cells[1].Text.ToString();  }

Advertisements

From → Uncategorized

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: