1SqlConnection conn = new SqlConnection("Data Source=;Initial Catalog=;Persist Security Info=True;User ID=;Password=");
2conn.Open();
3
4SqlCommand command = new SqlCommand("Select id from [table1] where name=@zip", conn);
5command.Parameters.AddWithValue("@zip","india");
6 // int result = command.ExecuteNonQuery();
7using (SqlDataReader reader = command.ExecuteReader())
8{
9 if (reader.Read())
10 {
11 Console.WriteLine(String.Format("{0}",reader["id"]));
12 }
13}
14
15conn.Close();
16
1DataSet ds = new DataSet();
2//https://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/ODPNET_Core_get_started/index.html
3using (SqlConnection con = new SqlConnection(connectionstr))
4{
5 using (SqlCommand cmd = con.CreateCommand())
6 {
7 con.Open();
8 cmd.CommandText = "select * from master.sys.server_principals";
9 SqlDataAdapter adapter = new SqlDataAdapter(cmd);
10 adapter.Fill(ds);
11 }
12}
1 SqlConnection conn = new SqlConnection("Database=student;Server=.;user=sa;password=aaaaaaa");
2 conn.Open(); // Open the connection
3 // body
4 // body
5 conn.Close(); // Close the connection