Click here to Skip to main content
16,016,345 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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-
C#
 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");
Posted
Updated 14-Feb-14 17:56pm
v2
Comments
[no name] 14-Feb-14 23:58pm    
share your table..
Member 10523130 15-Feb-14 0:05am    
CREATE TABLE [dbo].[login] (
[Id] INT IDENTITY (1, 1) NOT NULL,
[name] NCHAR (10) NULL,
[midname] NCHAR (10) NULL,
[surname] NCHAR (10) NULL,
[username] NCHAR (15) NULL,
[password] NCHAR (16) NULL,
[contact] NUMERIC (18) NULL,
[dob] VARCHAR (50) NULL,
[email] NVARCHAR (50) NULL,
[address] NVARCHAR (50) NULL,
[occupation] NCHAR (10) NULL,
[ltype] NCHAR (10) NULL,
[status] INT DEFAULT ((1)) NOT NULL,
[image] VARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)
);
this is my table
I guess you have not saved the table after adding new Column.
Member 10523130 15-Feb-14 0:06am    
i have saved my table.and i can see that column in my table
Are you in debugging mode right now in visual studio?
If yes, then stop debugging and run again.

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.
 
Share this answer
 
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900