下面的代码plz中的错误解决了任何一个 [英] error in this below code plz solve any one

查看:245
本文介绍了下面的代码plz中的错误解决了任何一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Line 29:         con.Open();
Line 30:         cmd = new SqlCommand("insert into login values('"+TextBox1.Text+"','"+TextBox3.Text+"'", con);
Line 31:         cmd.ExecuteNonQuery();
Line 32:     }
Line 33: 





using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;


public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    SqlConnection con = new SqlConnection("Data Source=CIODEV03\\SQLEXPRESS;Initial Catalog=EmployeeDB;Integrated Security=True");
    SqlCommand cmd;
    SqlDataReader dr;

    protected void Button1_Click(object sender, EventArgs e)
    {
        con.Open();
        cmd = new SqlCommand("insert into login values('"+TextBox1.Text+"','"+TextBox3.Text+"'", con);
        cmd.ExecuteNonQuery();
    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        con.Open();
        cmd = new SqlCommand("select * from login where UserName='" + TextBox1.Text + "'", con);
        dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            Label1.Text = "UserName alredy Exist";
            this.Label1.ForeColor = Color.Red;
        }
        else
        {
            Label1.Text = "UserName is Avilable";
        }
    }
}

推荐答案

确保您的字段名称与您要在此处插入的字符串值类型相匹配-new SqlCommand("insert into login values(''"+TextBox1.Text+"'',''"+TextBox3.Text+"''", con);.
Make sure your field names match the string value type that you are passing in for the insert here - new SqlCommand("insert into login values(''"+TextBox1.Text+"'',''"+TextBox3.Text+"''", con);.


cmd = new SqlCommand("insert into login values('"+TextBox1.Text+"','"+TextBox3.Text+"'", con);



至少没有)".尝试这样的事情:



At least there is no '')''. Try something like this:

cmd = new SqlCommand("insert into login values(@val1, @val2)", con);
cmd.Parameters.AddWithValue("@val1", TextBox1.Text);
cmd.Parameters.AddWithValue("@val2", TextBox3.Text);




确保登录表中的值等于登录时输入的值.

如果您的登录表中有2列,则必须通过codebehind传递2个参数.

这是正确的:
cmd = new SqlCommand(插入登录值(@ val1,@ val2)",con);
cmd.Parameters.AddWithValue("@ val1",TextBox1.Text);
cmd.Parameters.AddWithValue("@ val2",TextBox3.Text);

但是,如果要标识特定的列字段:
cmd = new SqlCommand(插入登录名(用户名,密码,日期)值(@ val1,@ val2,@ val3)",con);
cmd.Parameters.AddWithValue("@ val1",TextBox1.Text);
cmd.Parameters.AddWithValue("@ val2",TextBox3.Text);
cmd.Parameters.AddWithValue("@ val3",DateTime.Now());

希望这一点对您有所帮助.

谢谢
Hi,

Make sure the values in your Login Table is equal to values to enter upon login.

If you have 2 Columns in your Login table you must have 2 parameters to past via codebehind.

This is correct:
cmd = new SqlCommand("insert into login values(@val1, @val2)", con);
cmd.Parameters.AddWithValue("@val1", TextBox1.Text);
cmd.Parameters.AddWithValue("@val2", TextBox3.Text);

But if you want to identify the specific column fields:
cmd = new SqlCommand("insert into login (username, password, dates) values(@val1, @val2, @val3)", con);
cmd.Parameters.AddWithValue("@val1", TextBox1.Text);
cmd.Parameters.AddWithValue("@val2", TextBox3.Text);
cmd.Parameters.AddWithValue("@val3", DateTime.Now());

I hope this one can help.

Thank You


这篇关于下面的代码plz中的错误解决了任何一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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