void Insert()
{
try
{
string sql="insert into telnet_et_temp(zwup,zdsb,zusi)values(@zwup,@zdsb,@zusi)";
SqlParameter[] par={
new SqlParameter("@zwup",SqlDbType.Text,16),
new SqlParameter("@zdsb",SqlDbType.Text,16),
new SqlParameter("@zusi",SqlDbType.Text,16)};
par[0].Value=zwupstr;
par[1].Value=zdsbstr;
par[2].Value=zusistr;
using(SqlConnection cn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]))
{
cn.Open();
using(SqlCommand cm=cn.CreateCommand())
{
cm.CommandType=CommandType.Text;
cm.CommandText=sql;
foreach(SqlParameter spt in par)
{
cm.Parameters.Add(spt);
}
cm.ExecuteNonQuery();
}
}
MessageBox.Show("保存日志成功!");
}
catch (System.Exception e)
{
MessageBox.Show(e.Message);
}
}我的数据表里面的字段都是text类型,可是怎么老只插入了几个字符...
谢谢回复!!
new SqlParameter("@zwup",SqlDbType.Text,16),
new SqlParameter("@zdsb",SqlDbType.Text,16),
new SqlParameter("@zusi",SqlDbType.Text,16)};
里面的16是不是设置的太短了?
然后你是怎么知道没插入的?
用查询分析器,对于换行的文本是看不到的,只能看到第一行。