using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class CmdDataReadInsert : System.Web.UI.Page
{
private String Strconnection;
private String str;
private SqlConnection conn;
private SqlCommand cmd;
private SqlDataAdapter da;
protected void Page_Load(object sender, EventArgs e)
{
Strconnection= "Data Source =.; Initial Catalog = student; Integrated Security = True";
conn = new SqlConnection(Strconnection);
str = "select * from xsdata";
da = new SqlDataAdapter(str,conn);
SqlCommandBuilder cb = new SqlCommandBuilder();
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
conn.Open();
string sqltable = string.Format("select * from xsdata");
string insertstu = string.Format("insert into xsdata(Sxh,Sxm,Sxb,Scsrq,Szy,Sdk,Ssfzh,Sjg,Sjtdz)values ");
SqlDataAdapter da = new SqlDataAdapter(sqltable,conn);
DataSet ds = new DataSet();
da.Fill(ds);
DataRow dr = ds.Tables[0].NewRow();
dr["Sxh"] = this.Sxh.Text;
dr["Sxm"] = this.Sxm.Text;
dr["Sxb"] = this.Sxb.SelectedValue.ToString();
dr["Scsrq"] = Convert.ToDateTime(this.Scsrq.Text);
dr["Szy"] = this.Szy.SelectedValue.ToString();
dr["Sdk"] = this.Sdk.SelectedValue.ToString();
dr["Ssfzh"] = this.Ssfzh.Text;
dr["Sjg"] = this.Sjg.Text;
dr["Sjtdz"] = this.Sjtdz.Text;
ds.Tables[0].Rows.Add(dr);
da.InsertCommand = new SqlCommand(insertstu, conn);
da.Update(ds);
conn.Close();
}
catch (SqlException se)
{
Response.Write(se.Message.ToString());
}
}
}
}c# 连接数据库做插入功能 insert 语句的 values 应该怎么填
慕妹4321516
堂堂堂堂糖糖糖童鞋
随时随地看视频慕课网APP
相关分类