列名或提供的值数与表定义不匹配 [英] Column name or number of supplied values does not match table definition

查看:93
本文介绍了列名或提供的值数与表定义不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发现错误

列名或提供的值数与表定义不匹配







mycolumn名称都是正确的数据保存在数据库中但也显示错误



列名或提供的值数不匹配表定义

i m geting a error
Column name or number of supplied values does not match table definition



mycolumn name all are proper data is saving in databse but also showing a error

Column name or number of supplied values does not match table definition

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString());
        SqlCommand cmd = new SqlCommand();

        protected void Button1_Click(object sender, EventArgs e)
        {

            try
            {
                cmd.Connection = con; //assigning connection to command
                cmd.CommandType = CommandType.Text; //representing type of command

                cmd.CommandText = "insert into User_Register values(@Fname,@Lname,@UserID,@Password,@MobileNo,@Email,@ProfileImage)";

                //adding parameters with value
                cmd.Parameters.AddWithValue("@Fname", name.Text.ToString());
                cmd.Parameters.AddWithValue("@Lname", lname.Text.ToString());
                cmd.Parameters.AddWithValue("@UserID", userid.Text.ToString());
                cmd.Parameters.AddWithValue("@Password", password.Text.ToString());

                cmd.Parameters.AddWithValue("@MobileNo", cellno.Text.ToString());
                cmd.Parameters.AddWithValue("@Email", emailid.Text.ToString());

                int img = FileUpload1.PostedFile.ContentLength;

                byte[] msdata = new byte[img];

                FileUpload1.PostedFile.InputStream.Read(msdata, 0, img);

               cmd.Parameters.AddWithValue("@ProfileImage", msdata);
                con.Open(); //opening connection


                cmd.ExecuteNonQuery();  //executing query
                cmd.CommandText = "insert into login values('" + userid.Text + "','" + password.Text + "')";
                cmd.ExecuteNonQuery();
                Session["username"] = userid.Text;
                Session["password"] = password.Text;
             
                FormsAuthentication.RedirectFromLoginPage(userid.Text, true);
                con.Close(); //closing connection
               // ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Login Successfully...')</script>");
               // Label1.Text = "Registered Successfully..";
                Response.Redirect("default.aspx");

            }
            catch (System.Data.SqlClient.SqlException ex)
            {
                Label1.Text = ex.Message.ToString();
                
            }
        }
















<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="register.aspx.cs" Inherits="torqbolt.register" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

  <meta charset="UTF-8">

  <title>Torq Bolt Registration</title>

    <style>
@import url(http://fonts.googleapis.com/css?family=Exo:100,200,400);
@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:700,400,300);

body{
    margin: 0;
    padding: 0;
    background: #fff;

    color: #fff;
    font-family: Arial;
    font-size: 12px;
}

</style>

    <script src="js/prefixfree.min.js"></script>

</head>

<body>
    <form id="form1" runat="server">
<div class="body"></div>
<div class="grad"></div>
        <div class="header">
            <div>Site<span>Register</span></div>
        </div>
        <br>
        <div class="login">
          <asp:TextBox ID="name" runat="server" placeholder="First Name"  ></asp:TextBox><br />


     <asp:RequiredFieldValidator Display="Dynamic"  ID="RequiredFieldValidator6" runat="server"

                ControlToValidate="name" ForeColor="#FF3300" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>

        <asp:TextBox ID="lname" runat="server"  placeholder="Last Name"></asp:TextBox><br />
         <asp:RequiredFieldValidator Display="Dynamic"  ID="RequiredFieldValidator2" runat="server"

                ControlToValidate="lname" ForeColor="#FF3300" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>

         <asp:TextBox ID="userid" runat ="server"  placeholder="User Id" ></asp:TextBox><br />
          <asp:RequiredFieldValidator ID="RequiredFieldValidator4"  Display="Dynamic" runat="server"

                ControlToValidate="userid"

                ErrorMessage="It is a mandatory field Can't be left blank" ForeColor="#FF3300"></asp:RequiredFieldValidator>

           <asp:TextBox ID="password" runat="server" EnableViewState="true"  placeholder="Password"

                TextMode="Password" ></asp:TextBox><br />
                 <asp:RequiredFieldValidator ID="RequiredFieldValidator5" Display="Dynamic" runat="server"

                ForeColor="#FF3300" ControlToValidate="password" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>

                 <asp:TextBox ID="cellno" runat="server"  placeholder="Mobile No"></asp:TextBox><br />
                  <asp:RangeValidator ID="RangeValidator1" runat="server"

                          ForeColor="#FF3300" ControlToValidate="cellno" Display="Dynamic" ErrorMessage="Not in the correct format"

                                 MaximumValue="9999999999" MinimumValue="1000000000" Type="Double"></asp:RangeValidator>

                 <asp:TextBox ID="emailid" runat="server"  placeholder="Email ID"></asp:TextBox> <br />
                   <asp:RequiredFieldValidator Display="Dynamic" ID="RequiredFieldValidator3" runat="server"

                         ForeColor="#FF3300" ControlToValidate="emailid" ErrorMessage="It is a mandatory field Can't be left blank"></asp:RequiredFieldValidator>

            <asp:RegularExpressionValidator Display="Dynamic" ID="RegularExpressionValidator1" runat="server"

                 ForeColor="#FF3300" ControlToValidate="emailid" ErrorMessage="Not in the correct format i.e abc@domain"

                        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator><br>
    <asp:FileUpload ID="FileUpload1" runat="server" />

                    <asp:Button ID="Button1" runat="server" class="btn" Text="Submit" onclick="Button1_Click" />

                       <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
                        </div>
        <script src='http://codepen.io/assets/libs/fullpage/jquery.js'></script>
    </form>
</body>
</html>





my database





my database

create table User_Register (id numeric identity(1,1),
Fname varchar(100),Lname varchar(100),UserID varchar(100),
Password varchar(50),MobileNo numeric,Email varchar(70),
ProfileImage Image);
select * from User_Register







i m unable to undstnd wht to do now..




i m unable to undstnd wht to do now..

推荐答案

From your code it looks like you have problem in the following line.



From your code it looks like you have problem in the following line.

cmd.CommandText = "insert into login values('" + userid.Text + "','" + password.Text + "')";





Try following as suggested by kedar001 in the comment.





Try following as suggested by kedar001 in the comment.

cmd.CommandText = "insert into login (UserID,Password) values('" + userid.Text + "','" + password.Text + "')";





It is always recomended to use the full signature of INSERT to avoid these and few other kind of errors.



It is always recomended to use the full signature of INSERT to avoid these and few other kind of errors.


there was problem in my login table



cmd.CommandText = \"insert into login values(’\" + userid.Text + \"’,’\" + password.Text + \"’)\";



this is my login code



and in m login table der was 3 column and ws passing a data in 2 column.. now its solve



thnx ...



Suvendu Shekhar Giri
there was problem in my login table

cmd.CommandText = "insert into login values('" + userid.Text + "','" + password.Text + "')";

this is my login code

and in m login table der was 3 column and ws passing a data in 2 column.. now its solve

thnx ...

Suvendu Shekhar Giri


这篇关于列名或提供的值数与表定义不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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