无法在数据库中找到列 [英] Could not find a column in database

查看:100
本文介绍了无法在数据库中找到列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了webform,其中我编写了正确执行的插入查询。现在我已经在我的上一个表格中添加了一个字段,即image.and我已经在我的webform中添加了image列。在修改此表和webform之前,我的插入查询工作正常。但是在添加它之后它给了我异常为在数据库中找不到列,即使我的表显示新列image。我的插入查询失败。有什么问题?请帮忙。

这是我的代码 -

I created webform in which i have written insert query which was executing correctly. Now i have added one more field to my previous table i.e image.and i have added image column in my webform too. Before modifying this table and webform my insert query was working correctly.But after adding this it is giving me exception as "could not find column in databse", even though my table is showing that new column "image".and my insert query fails. What is the problem?please help.
this is my code-

 SqlConnection conn = new SqlConnection("Data Source=SNEHAL-PC\\SNEHAL1;Initial Catalog=TEMPRUJU;Integrated Security=True");
       SqlCommand cmd;
cmd = new SqlCommand("insert into login(name,midname,surname,username,password,contact,dob,email,address,occupation,ltype,image) values('" + txtfirst.Text + "','" + txtmid.Text + "','" + txtsur.Text + "','" + txtname.Text + "','" + txtpass.Text + "','" + txtcontact.Text + "','" + txtdob.Text + "','" + txtemail.Text + "','" + txtaddr.Text + "','" + txtocc.Text + "','" + typeButtonList1.SelectedValue + "','"+image1.ImageUrl+"')", conn);
                        cmd.ExecuteNonQuery();
                       Response.Redirect("WebForm1.aspx");

推荐答案

您在图像列数据类型中出错了。您应该使用图像数据类型或二进制数据类型声明图像列。你应该将上传的文件转换为特定的数据类型意味着图像或二进制。
You did a mistake in image column data type. you should declare image column with image data type or binary data type. And you should convert the uploaded file to specific data type means image or binary.


你错过了插入查询中的列'状态'。



cmd = new SqlCommand(插入登录名(姓名,姓名,姓名,用户名,密码,联系人,dob,电子邮件,地址,职业,ltype,状态,图像)值('+ txtfirst.Text + ','+ txtmid.Text +','+ txtsur.Text +','+ txtname.Text +','+ txtpass.Text +','+ txtcontact.Text + ','+ txtdob.Text +','+ txtemail.Text +','+ txtaddr.Text +','+ txtocc.Text +','+ typeButtonList1.SelectedValue + ','+ image1.ImageUrl +'),conn);
You missed a column 'status' in insert query.

cmd = new SqlCommand("insert into login(name,midname,surname,username,password,contact,dob,email,address,occupation,ltype,status,image) values('" + txtfirst.Text + "','" + txtmid.Text + "','" + txtsur.Text + "','" + txtname.Text + "','" + txtpass.Text + "','" + txtcontact.Text + "','" + txtdob.Text + "','" + txtemail.Text + "','" + txtaddr.Text + "','" + txtocc.Text + "','" + typeButtonList1.SelectedValue + "','"+image1.ImageUrl+"')", conn);


这篇关于无法在数据库中找到列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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