I have this code which shows the database I created using SqlClient
, but I don't know how I could check if a column was added as nullable or not nullable in the table.
string[] defaultTables = { "AspNetUsers", "AspNetRoleClaims", "AspNetUserClaims", "AspNetUserLogins", "AspNetUserRoles", "AspNetUserTokens", "AspNetRoles", "__EFMigrationsHistory" };
dblist.ForEach((string DbName) => {
strConnection = $@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog={DbName};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
using (SqlConnection conn = new SqlConnection(strConnection)) {
conn.Open();
using (cmdSql = new SqlCommand(strConnection, conn)) {
DataTable dt = conn.GetSchema("Tables");
foreach (DataRow row in dt.Rows) {
string tablename = row[2].ToString();
if (!defaultTables.Any(x => x == tablename)) {
tables.Add(tablename);
using (cmdSql = new SqlCommand($"Select * FROM {tablename}", conn)) {
SqlDataReader reader = cmdSql.ExecuteReader();
if (reader.Read()) {
for (int i = 0; i < reader.FieldCount; i++)
Console.Write(reader.GetName(i) + " " + reader.GetDataTypeName(i) + $"" + ',');
}
}
}
}
}
}
});