I was trying something like this
SqlDataAdapter da;
DataSet ds = new DataSet();
string conString = @"server = .\\sqlexpress;
integrated security = true;
database = northwind";
da = new SqlDataAdapter("select \* from employees", conString);
da.Fill(ds);
DataTable table = ds.Tables\[0\];
string conString2 = @"server = .\\sqlexpress;
integrated security = true;
database = ABZ";
string commandString = "Create table Employees ( ";
SqlConnection con = new SqlConnection(conString2);
DataTable tab = new DataTable("Employees");
foreach (DataColumn column in table.Columns )
{
commandString = commandString + column.ColumnName +" nvarchar (50), " ;
}
commandString = commandString + ")";
SqlCommand cmd = new SqlCommand(commandString, con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Table Created");
But the prob was I was getting a -1 value for column.MaxLength when I was trying this
foreach (DataColumn column in table.Columns )
{
commandString = commandString + column.ColumnName +" nvarchar (" + column.MaxLength + "), " ;
}
But how do you suggest I use the Select statement?