Please find the following code for connecting with DB
SqlConnection connection = new SqlConnection("Data Source=MACK;Initial Catalog=student;User ID=sa;Password=sourav321");
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "insert into student(id, username, password, name, email) values(@id, @uname, @password, @name, @email)";
command.Parameters.Add("@uname", UserName.Text);
command.Parameters.Add("@password", Password.Text);
command.Parameters.Add("@name", Name.Text);
command.Parameters.Add("@email", Email.Text);
command.Parameters.Add("@id", Guid.NewGuid().ToString());
connection.Open();
command.ExecuteNonQuery();
connection.Close();
SqlConnection connection = new SqlConnection("Data Source=MACK;Initial Catalog=student;User ID=sa;Password=sourav321");
SqlCommand command = new SqlCommand();
command.Connection = connection;
command.CommandText = "insert into student(id, username, password, name, email) values(@id, @uname, @password, @name, @email)";
command.Parameters.Add("@uname", UserName.Text);
command.Parameters.Add("@password", Password.Text);
command.Parameters.Add("@name", Name.Text);
command.Parameters.Add("@email", Email.Text);
command.Parameters.Add("@id", Guid.NewGuid().ToString());
connection.Open();
command.ExecuteNonQuery();
connection.Close();
No comments:
Post a Comment