My HTML:-
<table class="abtus">
<tr>
<td class="style2">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
<td class="style1">
<asp:FileUpload ID="FileUpload1" runat="server" />
</td>
<td>
<asp:TextBox ID="TextBox2" runat="server" CssClass="txtbx"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
<td class="style1">
<asp:FileUpload ID="FileUpload2" runat="server" />
</td>
<td>
<asp:TextBox ID="TextBox3" runat="server" CssClass="txtbx"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label3" runat="server" Text="Label"></asp:Label>
</td>
<td class="style1">
<asp:FileUpload ID="FileUpload3" runat="server" />
</td>
<td>
<asp:TextBox ID="TextBox4" runat="server" CssClass="txtbx"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label4" runat="server" Text="Label"></asp:Label>
</td>
<td class="style1">
<asp:FileUpload ID="FileUpload4" runat="server" />
</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" CssClass="txtbx"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label5" runat="server" Text="Label"></asp:Label>
</td>
<td class="style1">
<asp:FileUpload ID="FileUpload5" runat="server" />
</td>
<td>
<asp:TextBox ID="TextBox6" runat="server" CssClass="txtbx"></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label6" runat="server" Text="Label"></asp:Label>
</td>
<td class="style1">
<asp:FileUpload ID="FileUpload6" runat="server" />
</td>
<td>
<asp:TextBox ID="TextBox7" runat="server" CssClass="txtbx"></asp:TextBox>
</td>
</tr>
</table>
C# Code:-
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
uploadimage(Label1,FileUpload1,TextBox2);
}
if (FileUpload2.HasFile)
{
uploadimage(Label2, FileUpload2,TextBox3);
}
if (FileUpload3.HasFile)
{
uploadimage(Label3, FileUpload3,TextBox4);
}
if (FileUpload4.HasFile)
{
uploadimage(Label4, FileUpload4,TextBox5);
}
if (FileUpload5.HasFile)
{
uploadimage(Label5, FileUpload5,TextBox6);
}
if (FileUpload6.HasFile)
{
uploadimage(Label6, FileUpload6,TextBox7);
}
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Pictures Uploaded Successfully')", true);
}
public void uploadimage(Label l1, FileUpload f1, TextBox t1)
{
string str = @"data source=DEEPAKSHARMA-PC\SQLEXPRESS;initial catalog=new; integrated security=true";
SqlConnection con = new SqlConnection(str);
con.Open();
string s = Server.MapPath("Img/") + f1.FileName;
f1.SaveAs(s);
Here I want to add a new record with column name as RefrenceNo:-
SqlDataAdapter da = new SqlDataAdapter("Select count(*)+1 from as d from date1", con);
string query = "insert into date1 values('"+Label1.Text+"','" + TextBox1.Text + "','" + f1.FileName + "','" + t1.Text + "')";
SqlCommand cmd = new SqlCommand(query, con);
cmd.ExecuteNonQuery();
con.Close();
}