string strtext = T1.Text.ToString();
string[] words = strtext.Split(' ');
{
string strcon = @"Data Source=RAJA;Initial Catalog=ram;User Id=;Password=;Trusted_Connection=True; ";
//string strcon = "Server=RAJA\SQLEXPRESS;Database=ram;Trusted_Connection=True;";
SqlCommand cmdinserted = new SqlCommand();
SqlConnection con = new SqlConnection(strcon);
cmdinserted.CommandText =
"Insert into tooto VALUES ( '" + words[0].ToString() + "','" + words[1].ToString() + "','" + words[2].ToString() + "')";
cmdinserted.CommandTimeout = 0;
cmdinserted.CommandType =
CommandType.Text;
cmdinserted.Connection = con;
try
{
con.Open();
cmdinserted.ExecuteNonQuery();
con.Close();
}
catch (ArgumentOutOfRangeException ex)
{
Label2.Text = ex.Message.ToString();
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
string strtext = T1.Text.ToString();
//string[]words = strtext.Split(' ');
// if ((strtext.StartsWith("(")) && (strtext.EndsWith(")")))
if (strtext.Length == 12 && strtext.StartsWith("(") && strtext.EndsWith(")"))
{
string strcon = @"Data Source=RAJA;Initial Catalog=ram;User Id=;Password=;Trusted_Connection=True; ";
//string strcon = "Server=RAJA\SQLEXPRESS;Database=ram;Trusted_Connection=True;";
SqlCommand cmdinserted = new SqlCommand();
SqlConnection con = new SqlConnection(strcon);
cmdinserted.CommandText =
"Insert into punya VALUES ( '" + T1.Text + "')";
cmdinserted.CommandTimeout = 0;
cmdinserted.CommandType =
CommandType.Text;
cmdinserted.Connection = con;
try
{
con.Open();
cmdinserted.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Label2.Text = ex.Message.ToString();
}
}
else
{
string strcon = @"Data Source=RAJA;Initial Catalog=ram;User Id=;Password=;Trusted_Connection=True; ";
//string strcon = "Server=RAJA\SQLEXPRESS;Database=ram;Trusted_Connection=True;";
SqlCommand cmdinserted = new SqlCommand();
SqlConnection con = new SqlConnection(strcon);
cmdinserted.CommandText =
"Insert into punya1 VALUES ( '" + T1.Text + "')";
cmdinserted.CommandTimeout = 0;
cmdinserted.CommandType =
CommandType.Text;
cmdinserted.Connection = con;
try
{
con.Open();
cmdinserted.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{
Label2.Text = ex.Message.ToString();
}
}
hello sir good morning,
it is complet program but i want to make one connection and insert all data in database.plz quik reply me..