TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Gaurav Goyal
NA
21
6.1k
how to Dynamically create GridView or HTMl table frm dataset
May 8 2015 2:26 AM
Hi Everyone,
I have to generate a WebApplication in which I need to excecute sql files which contains multiple select staments.
I have created Application and I am able to retrieve multiple table in dataset.
But not able to create gridview dynamically..
My code is like this
code under pageload
SqlCommand cmd;
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
Boolean fileOK = false;
if (FileUpload1.HasFile)
{
String fileExtension = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
String[] allowedExtensions = { ".sql", ".txt" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (fileExtension == allowedExtensions[i])
{
fileOK = true;
}
}
}
if (fileOK)
{
string path = FileUpload1.PostedFile.FileName;
System.IO.StreamReader sr = new System.IO.StreamReader(path);
string line;
StringBuilder sb = new StringBuilder();
int counter = 0;
while ((line = sr.ReadLine()) != null)
{
sb.AppendLine(line);
counter++;
}
string command = sb.ToString();
cmd = new SqlCommand(command, conn);
DataSet ds = new DataSet();
try
{
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
}
catch (Exception ex)
{
}
finally
{
conn.Close();
}
}
else
{
Response.Write("Please select a sql or text file");
}
Reply
Answers (
2
)
How to Use Circular Progressbar in C#
DataTable records exports to csv