Firstly, create a Database and Table in the Microsoft Azure SQL Database. Here's the screenshot:
After creating the DB connect the Database using SQL Server.
Go to Server Explorer Object Explorer and Add connection.
Get the server name and login credential from https://manage.windowsazure.com. And login to the server using the SQL Server
After login to the server it shows the database in the Server Explorer Object Explorer Window like the following screenshot:
Now create the table using New Query. (I have created a table with two columns namely Name and Age. We can create any number of columns like the normal DB)
After creating the table, the explorer will look like the following:
Now its time for us to write the code. Create a form with two text box, two label and a command button.
Enter the following code inside the command button.
- String name = textBox1.Text.ToString();
- String age = textBox2.Text.ToString();
- SqlConnection con = new SqlConnection("Your connection String with password");
- con.Open();
- String query = "INSERT INTO dbo.demo (Name, Age) VALUES ('" + name.ToString() + "','" + age.ToString() + "' );";
- SqlCommand cmd = new SqlCommand(query, con);
- cmd.ExecuteNonQuery();
- MessageBox.Show("Sucessfully inseted");
After insertion of the data check with the db.
We can check the Dashboard.
Have fun.
No comments:
Post a Comment