datasource作为savefile对话框文件名 [英] datasource as savefile dialog filename

查看:94
本文介绍了datasource作为savefile对话框文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我到目前为止。

以下函数用于填充数据表。

This is what I have so far.
The following function is to fill the data table.

public void FillDT()
        {
            OleDbConnectionStringBuilder sb;
            sb = new OleDbConnectionStringBuilder();
            sb.Provider = "Provider=Microsoft.Jet.OLEDB.4.0;";
            sb.PersistSecurityInfo = false;
            sb.Add("Jet OLEDB:Database Password", "123456");
            SaveFileDialog sfd = new SaveFileDialog();
            if ((sb == null || sb.DataSource != null) && (sfd.FileName != null))
            {
                sb = new OleDbConnectionStringBuilder();
                sb.DataSource = sfd.FileName;
                return;
            }


            bookConn = new OleDbConnection(sb.Provider + "@Data Source=" + sb.DataSource + ";" + sb.PersistSecurityInfo);
            bookConn.Open();
            oleDbCmd.Connection = bookConn;

            oleDbCmd.CommandText = "INSERT INTO students (Firstname,Lastname,Age,Gender,School,Gfirstname,Glastname,Contact,Occupation,PostalAddr) Values('" + this.FirstnameTB.Text + "','" + this.LastnameTB.Text + "','" + this.AgeTB.Text + "','" + this.GenderTB.Text + "','" + this.SchoolTB.Text + "','" + this.GFirstnameTB.Text + "','" + this.GLastnameTB.Text + "','" + this.ContactTB.Text + "','" + this.OccupationTB.Text + "','" + this.AddressTB.Text + "');";
            int temp = oleDbCmd.ExecuteNonQuery();

            if (temp > 0)
            {
                FirstnameTB.Text = null;
                LastnameTB.Text = null;
                AgeTB.Text = null;
                GenderTB.Text = null;
                SchoolTB.Text = null;
                GFirstnameTB.Text = null;
                GLastnameTB.Text = null;
                ContactTB.Text = null;
                OccupationTB.Text = null;
                AddressTB.Text = null;
                MessageBox.Show("Record Successfuly Added", "Entry Added");
            }
            else
            {
                MessageBox.Show("Failed to Add Record", "Entry failure");
            }
            bookConn.Close();
            
        }





请给我另一个解决方案。



函数无法填充数据表 MessageBox.Show(记录成功添加); 甚至不执行。



谢谢。



Please give me another solution to this.

The function fails to fill the data table the MessageBox.Show("Record Successfully Added"); does not even execute.

Thank you.

推荐答案

你没有显示你的保存文件,如果你这样做,你会在它出现时返回跑。我不知道你想在这里做什么,但是,很明显这是写的一半。您是否在调试器中完成了它?
You don''t show your savefiledialog, and if you did, you would return when it had run. I don''t see what you want to do here, but, it''s clear this is half written. Have you stepped through it in a debugger ?


这篇关于datasource作为savefile对话框文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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