Y
yemingyu
Unregistered / Unconfirmed
GUEST, unregistred user!
public static int Add(HardWare hd)
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = _connstr;
//cmd.Connection =connection;
string cmdText = "Insert into Hard (Name,TypeName,Price,CurPosition,Sailer,UserName,Driver,Description,BM,IP,MAC) VALUES(@Name,@TypeName,@Price,@CurPosition,@Sailer,@UserName,@Driver,@Description,@BM,@IP,@MAC)";
//cmd.CommandText = cmdText;
OleDbCommand command = new OleDbCommand(cmdText,connection);
command.Parameters.Add(new OleDbParameter("@Name",OleDbType.Char ,30));
command.Parameters["@Name"].Value = hd.Name;
command.Parameters.Add( new OleDbParameter("@TypeName",OleDbType.Char,20));
command.Parameters["@TypeName"].Value= hd.TypeName;
command.Parameters.Add( new OleDbParameter("@Price",OleDbType.Integer,4));
command.Parameters["@Price"].Value=hd.Price;
command.Parameters.Add( new OleDbParameter("@BM",OleDbType.Integer,4));
command.Parameters["@BM"].Value = hd.DW;
command.Parameters.Add( new OleDbParameter("@CurPosition",OleDbType.Char,50));
command.Parameters["@CurPosition"].Value =hd.CurPosition;
command.Parameters.Add( new OleDbParameter("@Sailer",OleDbType.Char,50));
command.Parameters["@Sailer"].Value = hd.Sailer;
command.Parameters.Add( new OleDbParameter("@UserName",OleDbType.Char,20));
command.Parameters["@UserName"].Value = hd.UserName;
command.Parameters.Add( new OleDbParameter("@Driver",OleDbType.Char,200));
command.Parameters["@Driver"].Value =hd.Driver;
command.Parameters.Add( new OleDbParameter("@Description",OleDbType.Char,200));
command.Parameters["@Description"].Value = hd.Description;
command.Parameters.Add( new OleDbParameter("@IP",OleDbType.Char,15));
command.Parameters["@IP"].Value = hd.IP ;
command.Parameters.Add( new OleDbParameter("@MAC",OleDbType.Char,20));
command.Parameters["@MAC"].Value = hd.MAC ;
connection.Open();
int i = command.ExecuteNonQuery();
}
其中,HardWare是我自己写的一个类,问题不在这里。通过调试,我看到传进来的参数都是对的,后台数据库是ACCESS,可是一写到数据库中,却全乱了。除了Name,IP,MAC三个参数的值是正确的外,其他的几个全不是自己应该有的值,互相交叉了,意思是原本是A的变成了B,原本是B的值却是C。这是为什么?请指教,在线等。[!]
{
OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = _connstr;
//cmd.Connection =connection;
string cmdText = "Insert into Hard (Name,TypeName,Price,CurPosition,Sailer,UserName,Driver,Description,BM,IP,MAC) VALUES(@Name,@TypeName,@Price,@CurPosition,@Sailer,@UserName,@Driver,@Description,@BM,@IP,@MAC)";
//cmd.CommandText = cmdText;
OleDbCommand command = new OleDbCommand(cmdText,connection);
command.Parameters.Add(new OleDbParameter("@Name",OleDbType.Char ,30));
command.Parameters["@Name"].Value = hd.Name;
command.Parameters.Add( new OleDbParameter("@TypeName",OleDbType.Char,20));
command.Parameters["@TypeName"].Value= hd.TypeName;
command.Parameters.Add( new OleDbParameter("@Price",OleDbType.Integer,4));
command.Parameters["@Price"].Value=hd.Price;
command.Parameters.Add( new OleDbParameter("@BM",OleDbType.Integer,4));
command.Parameters["@BM"].Value = hd.DW;
command.Parameters.Add( new OleDbParameter("@CurPosition",OleDbType.Char,50));
command.Parameters["@CurPosition"].Value =hd.CurPosition;
command.Parameters.Add( new OleDbParameter("@Sailer",OleDbType.Char,50));
command.Parameters["@Sailer"].Value = hd.Sailer;
command.Parameters.Add( new OleDbParameter("@UserName",OleDbType.Char,20));
command.Parameters["@UserName"].Value = hd.UserName;
command.Parameters.Add( new OleDbParameter("@Driver",OleDbType.Char,200));
command.Parameters["@Driver"].Value =hd.Driver;
command.Parameters.Add( new OleDbParameter("@Description",OleDbType.Char,200));
command.Parameters["@Description"].Value = hd.Description;
command.Parameters.Add( new OleDbParameter("@IP",OleDbType.Char,15));
command.Parameters["@IP"].Value = hd.IP ;
command.Parameters.Add( new OleDbParameter("@MAC",OleDbType.Char,20));
command.Parameters["@MAC"].Value = hd.MAC ;
connection.Open();
int i = command.ExecuteNonQuery();
}
其中,HardWare是我自己写的一个类,问题不在这里。通过调试,我看到传进来的参数都是对的,后台数据库是ACCESS,可是一写到数据库中,却全乱了。除了Name,IP,MAC三个参数的值是正确的外,其他的几个全不是自己应该有的值,互相交叉了,意思是原本是A的变成了B,原本是B的值却是C。这是为什么?请指教,在线等。[!]