Hi,
How can I create a database on Button Click. What will be sql command. Plz, help
Thanks.
How to create database on button click
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Prabhu RajaRank #861 · 2.6K reputationPosted Sep 27, 2011, 9:10 PM EDT
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
Pravin MoreRank #1,419 · 1.2K reputationPosted Sep 27, 2011, 10:16 PM EDT
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.