怎么把datase的数据添加到数据库中
1个回答
2018-09-20 · 百度知道官方认证企业
腾讯电脑管家
腾讯电脑管家是腾讯公司推出的免费安全管理软件,能有效预防和解决计算机上常见的安全风险,并帮助用户解决各种电脑“疑难杂症”、优化系统和网络环境,是中国综合能力最强、最稳定的安全软件。
向TA提问
关注
展开全部
把数据添加到sql中
string sql = "INSERT INTO tbStudent VALUES (@Name,@Ware,@Model,@Number,@Sale,@Opinion,@Bonus)";
//string sql = "INSERT INTO tbStudent VALUES(@sNo,@sName,@sSex,@sAge)";
// 产生命令对象
SqlDataAdapter sqlAdap = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(sql, sqlcon);
sqlAdap.InsertCommand = cmd;
// 设置参数
SqlParameter pa = cmd.Parameters.Add("@Name", SqlDbType.VarChar, 20);
pa.SourceColumn = "Name";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Ware", SqlDbType.VarChar, 20);
pa.SourceColumn = "Ware";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Model", SqlDbType.VarChar, 20);
pa.SourceColumn = "Model";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Number", SqlDbType.Int, 4);
pa.SourceColumn = "Number";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Sale", SqlDbType.Money, 20);
pa.SourceColumn = "Sale";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Opinion", SqlDbType.VarChar, 20);
pa.SourceColumn = "Opinion";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Bonus", SqlDbType.Float, 8);
pa.SourceColumn = "Bonus";
pa.SourceVersion = DataRowVersion.Current;
try
{
sqlAdap.Update(ds.Tables[0]);
ds.Tables[0].AcceptChanges();
MessageBox.Show("添加成功!");
}
catch (Exception ex)
{
MessageBox.Show("添加失败!错误描述为:" + ex.Message);
}
}
string sql = "INSERT INTO tbStudent VALUES (@Name,@Ware,@Model,@Number,@Sale,@Opinion,@Bonus)";
//string sql = "INSERT INTO tbStudent VALUES(@sNo,@sName,@sSex,@sAge)";
// 产生命令对象
SqlDataAdapter sqlAdap = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand(sql, sqlcon);
sqlAdap.InsertCommand = cmd;
// 设置参数
SqlParameter pa = cmd.Parameters.Add("@Name", SqlDbType.VarChar, 20);
pa.SourceColumn = "Name";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Ware", SqlDbType.VarChar, 20);
pa.SourceColumn = "Ware";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Model", SqlDbType.VarChar, 20);
pa.SourceColumn = "Model";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Number", SqlDbType.Int, 4);
pa.SourceColumn = "Number";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Sale", SqlDbType.Money, 20);
pa.SourceColumn = "Sale";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Opinion", SqlDbType.VarChar, 20);
pa.SourceColumn = "Opinion";
pa.SourceVersion = DataRowVersion.Current;
pa = cmd.Parameters.Add("@Bonus", SqlDbType.Float, 8);
pa.SourceColumn = "Bonus";
pa.SourceVersion = DataRowVersion.Current;
try
{
sqlAdap.Update(ds.Tables[0]);
ds.Tables[0].AcceptChanges();
MessageBox.Show("添加成功!");
}
catch (Exception ex)
{
MessageBox.Show("添加失败!错误描述为:" + ex.Message);
}
}
光点科技
2023-08-15 广告
2023-08-15 广告
通常情况下,我们会按照结构模型把系统产生的数据分为三种类型:结构化数据、半结构化数据和非结构化数据。结构化数据,即行数据,是存储在数据库里,可以用二维表结构来逻辑表达实现的数据。最常见的就是数字数据和文本数据,它们可以某种标准格式存在于文件...
点击进入详情页
本回答由光点科技提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询