Maybe someone can help me with the following problem. what i want to achieve is to get all rows of a table and put them in a string with comma between each value. The result should be a scriptfile to get all of the rowdata in the table.
For so far:
static void Main(string[] args) {
StringBuilder builder = new StringBuilder();
string ConString = @"Data Source=.;Initial Catalog=USR;Integrated Security=True";
foreach (string itemtablename in TableNames())
{
Schema schema = new Schema();
schema.TableName = itemtablename; //the name of the table
//int i = 0;
string queryvalues = "select * from " + itemtablename;
SqlConnection conValues = new SqlConnection(ConString);
using (conValues)
{
conValues.Open();
SqlCommand cmdSchemaValues = new SqlCommand(queryvalues, conValues);
SqlDataReader readerSchemaValues = cmdSchemaValues.ExecuteReader();
DataTable dataTable = readerSchemaValues.GetSchemaTable();
//builder.AppendLine("INSERT INTO " + itemtablename);
//builder.AppendLine(" VALUES (");
for (int i = 0; i < dataTable.Rows.Count; i++)
{
string rowValues= dataTable.Rows[i].ToString() + ",";
builder.Append(rowValues);
}
}
}
System.IO.File.WriteAllText(@"C:\script.txt", builder.ToString());
}