Hi nedash,
Refer the below code. First you need to read the txt file from FileUpload control using StreamReader and then execute the code to insert the record to table.
C#
protected void Restore(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(FileUpload1.PostedFile.InputStream);
string data = sr.ReadToEnd();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString);
SqlCommand cmd = new SqlCommand(data, con);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
VB.Net
Protected Sub Restore(sender As Object, e As EventArgs)
Dim sr As New StreamReader(FileUpload1.PostedFile.InputStream)
Dim data As String = sr.ReadToEnd()
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings(1).ConnectionString)
Dim cmd As New SqlCommand(data, con)
cmd.CommandType = CommandType.Text
cmd.Connection = con
con.Open()
cmd.ExecuteNonQuery()
con.Close()
End Sub