Click here to Skip to main content
15,905,782 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to open a popup window if click a button. Then from the popup window I insert some items.
If I click save button then data insert into sql server
Then Click a Refresh button and data will show in a dropdownList of the parent page.
Please help me.
Posted
Comments
Sergey Alexandrovich Kryukov 21-Mar-13 2:16am    
Please, application type or UI library used.
—SA
What have you tried so far ?

1 solution

Dear Mohi,
You need to specify what kind of popup window you want to make. (You can use link of a image to specify it)


And for inserting data in sql server you can use the following code:


C#
private void button2_Click(object sender, EventArgs e)
      {
 SqlConnection conn = new SqlConnection("Data Source:.;Initial Catalog=database_name;Integrated Security=true");
            SqlCommand cmd = new SqlCommand("Insert into table_name values(@a,@b)", conn);
            conn.Open();
            cmd.Parameters.AddWithValue("@a", textBox1.Text.ToString());
            cmd.Parameters.AddWithValue("@b", textBox2.Text.toString());
            cmd.ExecuteNonQuery();
            MessageBox.Show("You data has been saved successfully");
            conn.Close();

      }




Explanation of Coding:
First of all, in the click event of button1 I have created a connection to sql sever using SqlConnection. I have passed Data Source(Server Name),Initial Catalog(Database Name), Integrated Security as true(as my sql server was running on windows security) after that I have created command for sql db usig SqlCommand class from System.Data.SqlClient .
After that I have opened the connection state and added the specified parameters in the command.
Then I have executed the query and then displayed the message and then closed the connection.


Hope it helps! Happy Coding!!
Akky
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900