Hi,
How can I create a database on Button Click. What will be sql command. Plz, help
Thanks.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pravin MorePosted Sep 28, 2011, 2:16 AM
do it like this......
private void button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=yourservername;Persist Security Info=True;UserID=youruserID;Password=yourpassward");
con.Open();
string str = "CREATE DATABASE pravinCheck";
SqlCommand myCommand = new SqlCommand(str, con);
myCommand.ExecuteNonQuery();
MessageBox.Show("DB created....!!!");
}
You can set other properties of database accoerding to you need by just editing query.
if you want, you can take database name dynamically from textbox or somthing....n create query will like
string str = "CREATE DATABASE "+textBox1.Text;
Thanx,Hope it will help you,
Pravin.
Prabhu RajaPosted Sep 28, 2011, 1:10 AM
After Creation, you can check your database details by
sp_helpdb [ database_name ]
---------------------------------------------------------------------------------
If this post helps you, then mark as "Correct Answer"
Thank You