本文介绍了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.
推荐答案
这篇关于datasource作为savefile对话框文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!