Hi Kevin,
Kevin Burton
Is there any modification that I can do to the stored procedure to avoid setting the table names in code?
From my experience. it seems that its impossible to set the table names in the stored procedure. And I create a demo like below, by default, the first datatabales tablename is Table, and next datatables tablename is Table1, and so on, so you need rename your tablename in your code.
string connString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=Demo;Integrated Security=True"; DataSet ds = new DataSet(); using (SqlConnection connection = new SqlConnection(connString)) { connection.Open(); SqlDataAdapter sqlDA = new SqlDataAdapter(); SqlCommand command = new SqlCommand("GetMutiTable", connection); command.CommandType = CommandType.StoredProcedure; sqlDA.SelectCommand = command; sqlDA.Fill(ds); connection.Close(); } foreach (DataTable dt in ds.Tables) { Console.WriteLine(dt.TableName); } Console.ReadKey();
Best regards,
Klein Zhang