Run this script in sql server management studio
CREATE TABLE [dbo].[FileUploads](
[uid] [int] IDENTITY(1,1) NOT NULL,
[uname] [nvarchar](max) NULL,
[uimg] [nvarchar](max) NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
change the following line in the method:
SqlCommand cmd = new SqlCommand("insert into FileUploads values('" + TextBox1.Text + "','" + theFileName + "')", con);
Updated one:
protected void Button1_Click(object sender, EventArgs e)
{
string connectionString = "Put your connection string here";
if (FileUpload1.HasFile)
{
string theFileName = Path.Combine(Server.MapPath("~/Uploads"), FileUpload1.FileName);
using (var con = new SqlConnection(connectionString))
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into uploads values('" + TextBox1.Text + "','" + theFileName + "')", con);
cmd.ExecuteNonQuery();
}
if (File.Exists(theFileName))
{
File.Delete(theFileName);
}
FileUpload1.SaveAs(theFileName);
Label1.Text = "Image upload Successfully";
}
else
{
Label1.Text = "Plz select ur image and upload";
}
}
Don't forget to use your own connection string to the server.