Reputation: 1
I have a PostgreSql DB connected to Visual Studio. I want to change a column(what column I want) from null to not null via Visual Studio. How I can do that? Can't find this on internet.
Upvotes: 0
Views: 99
Reputation: 38
Try this code:
SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "ALTER TABLE YourTableName ALTER COLUMN YourColumnName DROP NOT NULL;";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
sqlConnection1.Close();
Upvotes: 1