public void Insert(int UserID, string UserName, string PassWord, string Tel)
{
var _adapter = new System.Data.SqlClient.SqlDataAdapter();
var InsertCommand = new System.Data.SqlClient.SqlCommand();
var _connection = new System.Data.SqlClient.SqlConnection();
_connection.ConnectionString = WebApplication4.Properties.
Settings.Default.db_sql20001ConnectionString;
InsertCommand.Connection = _connection;
InsertCommand.CommandText = "INSERT INTO [dbo].[tb_UserLogin] ([UserID], [UserName], [PassWord], [Tel]) VALUES" +
" (@UserID, @UserName, @PassWord, @Tel)";
InsertCommand.CommandType = System.Data.CommandType.Text;
InsertCommand.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.Int, 0, System.Data.ParameterDirection.Input, 0, 0, "UserID", System.Data.DataRowVersion.Current, false, null, "", "", ""));
InsertCommand.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.VarChar, 0, System.Data.ParameterDirection.Input, 0, 0, "UserName", System.Data.DataRowVersion.Current, false, null, "", "", ""));
InsertCommand.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@PassWord", System.Data.SqlDbType.VarChar, 0, System.Data.ParameterDirection.Input, 0, 0, "PassWord", System.Data.DataRowVersion.Current, false, null, "", "", ""));
InsertCommand.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Tel", System.Data.SqlDbType.VarChar, 0, System.Data.ParameterDirection.Input, 0, 0, "Tel", System.Data.DataRowVersion.Current, false, null, "", "", ""));
InsertCommand.Parameters[0].Value = ((int)(UserID));
if ((UserName == null))
{
InsertCommand.Parameters[1].Value = System.DBNull.Value;
}
else
{
InsertCommand.Parameters[1].Value = ((string)(UserName));
}
if ((PassWord == null))
{
InsertCommand.Parameters[2].Value = System.DBNull.Value;
}
else
{
InsertCommand.Parameters[2].Value = ((string)(PassWord));
}
if ((Tel == null))
{
InsertCommand.Parameters[3].Value = System.DBNull.Value;
}
else
{
InsertCommand.Parameters[3].Value = ((string)(Tel));
}
System.Data.ConnectionState previousConnectionState = InsertCommand.Connection.State;
if (((InsertCommand.Connection.State & System.Data.ConnectionState.Open)
!= System.Data.ConnectionState.Open))
{
InsertCommand.Connection.Open();
}
try
{
int returnValue = InsertCommand.ExecuteNonQuery();
}
finally
{
if ((previousConnectionState == System.Data.ConnectionState.Closed))
{
InsertCommand.Connection.Close();
}
}
}
public void Insert2(int UserID, string UserName, string PassWord, string Tel)
{
var _Command = new System.Data.SqlClient.SqlCommand();
var _connection = new System.Data.SqlClient.SqlConnection();
_connection.ConnectionString = WebApplication4.Properties.
Settings.Default.db_sql20001ConnectionString;
_Command.Connection = _connection;
//更新和删除跟增加类似,修改这里就好
_Command.CommandText = "INSERT INTO [dbo].[tb_UserLogin] ([UserID], [UserName], [PassWord], [Tel]) VALUES" +
" (@UserID, @UserName, @PassWord, @Tel)";
_Command.CommandType = System.Data.CommandType.Text;
_Command.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@UserID", System.Data.SqlDbType.Int, 0, System.Data.ParameterDirection.Input, 0, 0, "UserID", System.Data.DataRowVersion.Current, false, null, "", "", ""));
_Command.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@UserName", System.Data.SqlDbType.VarChar, 0, System.Data.ParameterDirection.Input, 0, 0, "UserName", System.Data.DataRowVersion.Current, false, null, "", "", ""));
_Command.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@PassWord", System.Data.SqlDbType.VarChar, 0, System.Data.ParameterDirection.Input, 0, 0, "PassWord", System.Data.DataRowVersion.Current, false, null, "", "", ""));
_Command.Parameters.Add(
new System.Data.SqlClient.SqlParameter("@Tel", System.Data.SqlDbType.VarChar, 0, System.Data.ParameterDirection.Input, 0, 0, "Tel", System.Data.DataRowVersion.Current, false, null, "", "", ""));
_Command.Parameters[0].Value = ((int)(UserID));
if ((UserName == null))
{
_Command.Parameters[1].Value = System.DBNull.Value;
}
else
{
_Command.Parameters[1].Value = ((string)(UserName));
}
if ((PassWord == null))
{
_Command.Parameters[2].Value = System.DBNull.Value;
}
else
{
_Command.Parameters[2].Value = ((string)(PassWord));
}
if ((Tel == null))
{
_Command.Parameters[3].Value = System.DBNull.Value;
}
else
{
_Command.Parameters[3].Value = ((string)(Tel));
}
System.Data.ConnectionState previousConnectionState = _Command.Connection.State;
if (((_Command.Connection.State & System.Data.ConnectionState.Open)
!= System.Data.ConnectionState.Open))
{
_Command.Connection.Open();
}
try
{
int returnValue = _Command.ExecuteNonQuery();
}
finally
{
if ((previousConnectionState == System.Data.ConnectionState.Closed))
{
_Command.Connection.Close();
}
}
}