zzh2000080015 2020-11-05 22:16
浏览 11

C#webform插入数据库错误

插入数据库数据库不显示。

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);
        }
    }
}

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求差集那个函数有问题,有无佬可以解决
    • ¥15 【提问】基于Invest的水源涵养
    • ¥20 微信网友居然可以通过vx号找到我绑的手机号
    • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
    • ¥15 解riccati方程组
    • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
    • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥65 汇编语言除法溢出问题