110,534
社区成员
发帖
与我相关
我的任务
分享
if(textBox_money.Text == "" || Cbb_program.Text == "")
{
MessageBox.Show("Error,请输入金额并完善项目列表,否则无法加入数据库 Code:03001");
return;
}
DateTime dt = Dtp_dateTimePicker.Value;//时间
string dtStr = dt.ToString("yyyy-MM-dd");
try
{
string connectstring = "Data Source=AccountDateBase11.mdb;Jet OleDb:Database";
string sqlcommand = "insert into [Account]([money],[time],[type],[program],[note]) values('" + textBox_money.Text + ",'" + dtStr + ",'" + Cbb_type.Text + ",'" + Cbb_program.Text + ",'" + textBox_note.Text + "')";
SqlConnection aConnection = new SqlConnection(connectstring);
aConnection.Open();
SqlCommand aCommand = new SqlCommand(sqlcommand, aConnection);//运行到这里报错从索引 34 处开始,初始化字符串的格式不符合规范
aCommand.ExecuteNonQuery();
textBox_money.Text = "";
textBox_note.Text = "";
MessageBox.Show("添加成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "系统错误");
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string strPro = this.textBox1.Text.Trim();
DateTime stTtime = Convert.ToDateTime(dateTimePicker1.Value.ToString("yyyy-MM-dd"));
string strType = comboBox1.Text;
//这里要做验证,字符串转decimal
decimal money = Convert.ToDecimal(textBox2.Text.Trim());
if (string.IsNullOrEmpty(strPro))
{
MessageBox.Show("请输入");
return;
}
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccountDateBase11.mdb");
conn.Open();
string sql = "insert into [Account]([program],[type],[time],[money]) values('" + strPro + "','"+ strType + "','" + stTtime + "','"+money+"')";
OleDbCommand com = new OleDbCommand(sql, conn);
int result = com.ExecuteNonQuery();
conn.Close();
MessageBox.Show("添加成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "系统错误");
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("类型1");
comboBox1.Items.Add("类型2");
comboBox1.SelectedIndex = 0;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApp12
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string strPro = this.textBox1.Text.Trim();
string stTtime = dateTimePicker1.Value.ToString("yyyy-MM-dd");
string strType = comboBox1.Text;
if (string.IsNullOrEmpty(strPro))
{
MessageBox.Show("请输入");
return;
}
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccountDateBase11.mdb");
conn.Open();
string sql = "insert into [Account]([program],[type],[time]) values('" + strPro + "','"+ strType + "','" + stTtime + "')";
OleDbCommand com = new OleDbCommand(sql, conn);
int result = com.ExecuteNonQuery();
conn.Close();
MessageBox.Show("添加成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "系统错误");
}
}
private void Form1_Load(object sender, EventArgs e)
{
comboBox1.Items.Add("类型1");
comboBox1.Items.Add("类型2");
comboBox1.SelectedIndex = 0;
}
}
}
try
{
string pro = this.textBox1.Text.Trim();
if (string.IsNullOrEmpty(pro))
{
MessageBox.Show("请输入");
return;
}
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=AccountDateBase11.mdb");
conn.Open();
string sql = "insert into [Account]([program]) values('"+ pro + "')";
OleDbCommand com = new OleDbCommand(sql, conn);
int result = com.ExecuteNonQuery();
conn.Close();
MessageBox.Show("添加成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "系统错误");
}