创建一个弹出窗口并刷新父窗口 [英] Make a popup window and Refresh parent window

查看:83
本文介绍了创建一个弹出窗口并刷新父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果点击按钮,我想打开一个弹出窗口。然后从弹出窗口我插入一些项目。

如果我点击保存按钮然后数据插入到sql server

然后单击一个刷新按钮,数据将显示在dropdownList中父页面。

请帮助我。

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.

推荐答案

亲爱的Mohi,

您需要指定什么样的你想要制作的弹出窗口。 (您可以使用图像的链接来指定它)





要在sql server中插入数据,您可以使用以下代码:





Dear Mo
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:


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();

      }









编码:

首先,在button1的click事件中,我使用SqlConnection创建了与sql sever的连接。我已经通过数据源(服务器名称),初始目录(数据库名称),集成安全性为真(因为我的sql服务器在Windows安全上运行)之后我已经从System.Data.SqlClient创建了sql db usig SqlCommand类的命令。

之后我打开了连接状态并在命令中添加了指定的参数。

然后我执行了查询然后显示了消息,然后关闭了连接。





希望它有所帮助!快乐的编码!!

Akky





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


这篇关于创建一个弹出窗口并刷新父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆