我从数据源获得错误,请验证这一点 [英] I got Error from data source, please verify this

查看:53
本文介绍了我从数据源获得错误,请验证这一点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    SqlConnection con = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename="C:\Users\SONY\Documents\Visual Studio 2010\WebSites\WebSite9\App_Data\Student.mdf";Integrated Security=True;User Instance=True");
        SqlCommand cmd;
    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        cmd = new SqlCommand("insert into Student values('"+TextBox1 .Text +"','"+TextBox2 .Text +"',)", con);
        cmd.ExecuteNonQuery();
       

    }
}

推荐答案

删除逗号(,)结束查询(在关闭paranthesis之前)。



你应该在你的问题中包含错误信息以便快速回答。



最后,你应该使用参数化查询来避免sql注入。
Remove the comma(,) end of the query(before closing paranthesis).

And you should inlcude the error message in your question to get quick answer.

Finally, you should use parameterized query to avoid sql injection.


这篇关于我从数据源获得错误,请验证这一点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆