why not use store procedure?
for example
in db
Create procedure sp_Insert
(
@Name varchar(50), @FatherName varchar(50), @Email varchar(20), @LandLineNo varchar(15), @MobileNo varchar(15),
@Country varchar(50), @Gender varchar(6)
)
as
Insert into registration (Name, Father Name, Email, Land Line No, Mobile No, Country,Gender)
VALUES (@Name, @Father Name, @Email, @Land Line No, @Mobile No, @Country, @Gender)
call store procedure in UI like button event
-------
try
{
sqlConnection = new SqlConnection(dbConnectionString);
SqlCommand command = new SqlCommand("sp_Insert", sqlConnection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@Name", SqlDbType.VarChar).Value = Name.Text;
command.Parameters.Add("@Father Name", SqlDbType.VarChar).Value = FatherName.Text;
command.Parameters.Add("@Email", SqlDbType.VarChar).Value = Email.Text;
command.Parameters.Add("@Land Line No", SqlDbType.VarChar).Value = LandLineNo.Text;
command.Parameters.Add("@Mobile No", SqlDbType.VarChar).Value = Mobile.Text;
command.Parameters.Add("@Country", SqlDbType.VarChar).Value = Country.Text;
command.Parameters.Add("@Gender", SqlDbType.VarChar).Value = Gender.Text;
sqlConnection.Open();
return command.ExecuteNonQuery();
sqlConnection.Close();
}
catch (SqlException ex)
{
Console.WriteLine("SQL Error" + ex.Message.ToString());
return 0;
}
try this