Segue uma dica simples, mas util para você cadastrar dados no seu banco com sua aplicação ASP.NET e C#:
public string GetConnectionString()
{
return System.Configuration.ConfigurationManager.ConnectionStrings["ConnStringName"].ConnectionString;
//sets the connection string from your web config file "ConnString" is the name of your Connection String
}
private void InsertInfo()
{
SqlConnection conn = new SqlConnection(GetConnectionString());
string sql = "INSERT INTO connect_com (name,E_mail,School ) VALUES (@Val1,@Val2,@Val3)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.AddWithValue("@Val1", txtName.Text);
cmd.Parameters.AddWithValue("@Val2", txtEmail.Text);
cmd.Parameters.AddWithValue("@Val3", txtSchool.Text);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Insert Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e){
InsertInfo();
}