列名称或提供的值不匹配! [英] Column name or supplied values does not match!!!

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

问题描述

继续向我抛出这个错误...



我创建了一个包含以下属性的费用信息表 -



exp_description varchar(500)not null,exp_date date,amount int not null。



表已成功创建..



在前端我有3个文本框用于这些条目。



我正在通过图像按钮使用日历控件。



代码是 -



Keeps throwing me this error...

I have created a expense information table with following attributes -

exp_description varchar (500) not null, exp_date date , amount int not null.

table was successfully created..

In the front end I have 3 text boxes for these entries.

I am making using a calender control by a image button.

the code is -

protected void ImageButton1_Click1(object sender, ImageClickEventArgs e)
{
    Calendar1.Visible = true;
}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
    TextBox3.Text = Convert.ToString(Calendar1.SelectedDate.ToShortDateString());

    Calendar1.Visible = false;
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{

}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{

}



protected void Button1_Click(object sender, EventArgs e)
{
    try
    {

        cmd = new SqlCommand("Insert into exp_info values(@exp_description,@exp_date,@amount)", con);
        cmd.Parameters.Add(new SqlParameter("@exp_description", TextBox1.Text));
        cmd.Parameters.Add(new SqlParameter("@exp_date", TextBox3.Text));
        cmd.Parameters.Add(new SqlParameter("@amount", Convert.ToInt32(TextBox2.Text )));

        int x = cmd.ExecuteNonQuery();
        if (x > 0)
        {
            msgbox("values inserted");

        }
    }

    catch (Exception exc){

        msgbox(exc.Message);

    }

}









我是asp.net的新手...请帮助/ ..





I am new in asp.net... Please help/..

推荐答案

你的第二列属于 date 但您正在尝试插入字符串(TextBox3.Text)。在创建SqlParameter之前,需要将TextBox3.Text的值转换为DateTime。请参阅 DateTime.TryParse(..) [ ^ ]



编辑:这与你已经使用第三列的值基本相同。 / edit



另外,你应该在insert语句中指定列名:

Your second column is of type date but you're trying to insert a string (TextBox3.Text). You need to convert the value of TextBox3.Text to a DateTime before creating the SqlParameter. See DateTime.TryParse(..)[^]

edit: It's basically the same thing like you already do with the value for the third column. /edit

Also, you should specify the column names in your insert-statement:
Insert into exp_info (exp_description,exp_date,amount) values(@exp_description,@exp_date,@amount)



这是一种很好的做法,可以在你想从insert-statement中省略一些列时防止错误。


It's good practice and will prevent errors when you want to leave out some column(s) from your insert-statement.


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

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