string SqlStr="insert into tablename values('','','','')"
SqlConnection sqlcn = new SqlConnection(......);
SqlCommand cmd = new SqlCommand(SqlStr,sqlcn);
try
{
sqlcn.Open();
cmd.NoneQueryExcute();
}
catch(SqlException ex)
{
  MessageBox.Show(ex.Message);
}
finally
{
  sqlcn.Close();
}

解决方案 »

  1.   

    SqlCommand mycommand=new SqlCommand(str,SqlConnection1);
    mycommand.EcecuteNonQuery();
    .....
      

  2.   

    SqlCommand mycommand=new SqlCommand(str,SqlConnection1);
    mycommand.ExecuteNonQuery();
    .....
      

  3.   

    SqlCommand cmd = new SqlCommand(Str,sqlcn);
    cmd.EcecuteNonQuery();
      

  4.   

    SqlCommand mycomsql=new SqlCommand(str,SqlConnection1);
    mycomsql.ExecuteNonQuery();
    .....
    ......
      

  5.   

    一个向表名为logName中插入一条message的方法:
    private static void LogMessage(string message , string logName)
    { SqlConnection connection = null;
                SqlCommand command = null;
    SqlTransaction myTrans;
    try
    {
    connection = new SqlConnection("……");
    string commandString = "INSERT INTO " + logName + " (status, creatTime) VALUES ('" + message + "',getdate())";
    command = new SqlCommand(commandString , connection);
    connection.Open(); myTrans = connection.BeginTransaction();
    command.Transaction = myTrans;

    int numrows = command.ExecuteNonQuery();
    myTrans.Commit();
    }
    catch( Exception ex )
    {
        MessageBox.Show(ex.Message);
    }
    finally
    {
    command.Dispose();
    connection.Close();
    }
    }