插入数据库数据库不显示。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
namespace WebApplication1
{
class A
{
public static SqlConnection con()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = @"Data Source=DESKTOP-BLOD1OH;Initial Catalog=text;Integrated Security=SSPI";
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
return conn;
}
public static SqlCommand cmd(SqlConnection conn, string sql)
{
SqlCommand comd = new SqlCommand();
comd.Connection = conn;
comd.CommandText = sql;
return comd;
}
public static void closed(SqlConnection conn)
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Label6.Text = TextBox1.Text + " , " + TextBox2.Text + " , " + TextBox3.Text + " , " + TextBox4.Text + " , " + TextBox5.Text;
}
protected void Button2_Click(object sender, EventArgs e)
{
string zh = TextBox1.Text;
string mm = TextBox2.Text;
string sf = TextBox3.Text;
string xm = TextBox4.Text;
string xb = TextBox5.Text;
string sql = "insert into dbo.userinfo(账号,密码,身份,姓名,性别) values('" + zh + "','" + mm + "','" + sf + "','" + xm + "','" + xb + "')";
SqlConnection conn = A.con();
SqlCommand comd = A.cmd(conn, sql);
A.closed(conn);
}
}
}