SqlConnection con = new SqlConnection("Initial Catalog=Dbname; Data Source=MySqlServer; User=testuser; Password=pass123;"); DataSet ds = new DataSet(); SqlCommand cmd = new SqlCommand("select * from TableName", con); cmd.CommandType = CommandType.Text; SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); DataColumn[] columns; columns = ds.Tables[0].PrimaryKey; // Get the number of elements in the array. Response.Write("Column Count: " + columns.Length); for (int i = 0; i < columns.Length; i++) { Response.Write(columns[i].ColumnName + columns[i].DataType); }
TableName
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)