How to make connection visual studio with sql server
<connectionStrings>
<add name="waki" connectionString="Data Source=WAQEEH\SQLEXPRESS;Initial Catalog=waki new;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
namespace VPProject
{
class studentclass
{
public DataTable GetData(string a)
{
DataTable dt;
using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["waki"].ConnectionString))
{
using (SqlCommand command = new SqlCommand())
{
command.CommandText = a;
command.Connection = con;
con.Open();
SqlDataReader sqlDataReader = command.ExecuteReader();
dt = new System.Data.DataTable();
dt.Load(sqlDataReader);
con.Close();
}
}
return dt;
}
public void SetData(string Querry)
{
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["waki"].ConnectionString))
{
using (SqlCommand command = new SqlCommand())
{
command.CommandText = Querry;
command.Connection = con;
con.Open();
command.ExecuteNonQuery();
con.Close();
}
}
}
}
}
var srchquery = string.Format("select * from [waqeeh 1] where Name = '{0}'",textBox1.Text);
studentclass s = new studentclass();
dataGridView1.DataSource = s.GetData(srchquery);
No comments:
Post a Comment