vladl
vladl

Reputation: 1

changing null to not null in postgresql via c#

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

Answers (1)

Save
Save

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

Related Questions