我会尽量明确:
我在做什么:我正在制作一个Outlook加载项,用于制作防火墙策略更改请求。加载项的一部分是用户输入IP地址。
我想要的是什么:从用户那里获取IP地址输入并将其添加到Mysql DB中,并在表单本身的DataGridView中显示添加的IP
请查看Here (the imgur link of the screenshot of the form)
我正在使用一个名为IP Address Control的自定义工具箱项来输入IP地址。以下是其文档:IP Address control:Github
我做了什么:
命名空间OutlookAddIn6 {
公共部分类Form1:表单
{
MySqlConnection mson = new MySqlConnection("datasource/localhost;port=3306,username=root,password=password");
MySqlCommand mcd;
MySqlDataReader mdr;
public Form1()
{
InitializeComponent();
}
// The following section is to make the frameless-form draggable :Begin
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_NCHITTEST)
m.Result = (IntPtr)(HT_CAPTION);
}
private const int WM_NCHITTEST = 0x84;
private const int HT_CLIENT = 0x1;
private const int HT_CAPTION = 0x2;
//::End::
private void button2_Click(object sender, EventArgs e) //Exit button
{
this.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'airtelWorkDataSet.table1' table. You can move, or remove it, as needed.
this.table1TableAdapter.Fill(this.airtelWorkDataSet.table1);
}
private void btn_add_Click(object sender, EventArgs e)
{
try
{
string strsql = "insert into table1 (ID,Source IP,Source Misc_ IP,Destination IP,Misc. Destination IP,Application,Protocol,Port)values('" + ipAddressControl1.Text + "','" + ipAddressControl2.Text + "','" + ipAddressControl3.Text + "','" + ipAddressControl4.Text + "','" + ipAddressControl5.Text + "','" + ipAddressControl6.Text + "','" + ipAddressControl7.Text + "')";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
mdr.Close();
mson.Close();
}
}
}
我的领域主要是Android Dev,所以我不熟悉sql连接,所以我提前道歉,因为我缺乏理解
我还需要在datagridview
中添加按钮来编辑和删除这些数据我没有人帮助我,所以任何帮助都会受到高度赞赏!
谢谢!