求救 c#从索引 33 处开始,初始化字符串的格式不符合规范
usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Da...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string ID = this.mane.Text;
string k1 = this.ke.Text;
string k2 = this.key2.Text;
string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;C:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\test\CMS_DataManager.mdb";
if (k1 != k2)
{
MessageBox.Show("两次输入的密码不一致 \n 请重新输入!");
return;
}
string m = "select strUserName from SysBldUserDefine where strUserName=this.mane.Text";
string i = "insert into SysBldUserDefine (strUserName,strUserPassword) values ('this.mane.Text','this.ke.Text')";
OleDbConnection conn = new OleDbConnection(conStr);
OleDbCommand cmd = new OleDbCommand(m,conn);\\ 报错位置 !!!!!!
try
{
conn.Open();
cmd.Parameters.Add(new OleDbParameter("mane", m));
int cnt = (int)cmd.ExecuteScalar();
if (cnt == 0)
{
cmd = new OleDbCommand(i, conn);
cmd.Parameters.Add(new OleDbParameter("strUserName", ID));
cmd.Parameters.Add(new OleDbParameter("strUserPassword", k1));
cmd.ExecuteNonQuery();
MessageBox.Show("注册成功!");
}
else
{
MessageBox.Show("该用户已存在 \n 请重新注册!");
}
}
catch(Exception ex)
{
MessageBox.Show("出现错误!");
}
finally
{
if (conn != null) conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
this.Hide();
f2.ShowDialog();
}
出现求救 c#从索引 33 处开始,初始化字符串的格式不符合规范
代码如上 求解决 谢谢 展开
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
string ID = this.mane.Text;
string k1 = this.ke.Text;
string k2 = this.key2.Text;
string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;C:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\test\CMS_DataManager.mdb";
if (k1 != k2)
{
MessageBox.Show("两次输入的密码不一致 \n 请重新输入!");
return;
}
string m = "select strUserName from SysBldUserDefine where strUserName=this.mane.Text";
string i = "insert into SysBldUserDefine (strUserName,strUserPassword) values ('this.mane.Text','this.ke.Text')";
OleDbConnection conn = new OleDbConnection(conStr);
OleDbCommand cmd = new OleDbCommand(m,conn);\\ 报错位置 !!!!!!
try
{
conn.Open();
cmd.Parameters.Add(new OleDbParameter("mane", m));
int cnt = (int)cmd.ExecuteScalar();
if (cnt == 0)
{
cmd = new OleDbCommand(i, conn);
cmd.Parameters.Add(new OleDbParameter("strUserName", ID));
cmd.Parameters.Add(new OleDbParameter("strUserPassword", k1));
cmd.ExecuteNonQuery();
MessageBox.Show("注册成功!");
}
else
{
MessageBox.Show("该用户已存在 \n 请重新注册!");
}
}
catch(Exception ex)
{
MessageBox.Show("出现错误!");
}
finally
{
if (conn != null) conn.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
this.Hide();
f2.ShowDialog();
}
出现求救 c#从索引 33 处开始,初始化字符串的格式不符合规范
代码如上 求解决 谢谢 展开
3个回答
推荐于2018-05-07
展开全部
你的连接字符串写错了。改成这个试试。
string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\test\CMS_DataManager.mdb";
string conStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\test\CMS_DataManager.mdb";
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看下下面的sql
string m = "select strUserName from SysBldUserDefine where strUserName="+this.mane.Text;
string i = "insert into SysBldUserDefine (strUserName,strUserPassword) values ('"+this.mane.Text+"','"+this.ke.Text+"')";
string m = "select strUserName from SysBldUserDefine where strUserName="+this.mane.Text;
string i = "insert into SysBldUserDefine (strUserName,strUserPassword) values ('"+this.mane.Text+"','"+this.ke.Text+"')";
更多追问追答
追问
OleDbCommand cmd = new OleDbCommand(m,conn);\\ 报错位置 !!!!!!
此处
追答
看下我给的m的拼法,按你的写法是搜索strUserName=’this.mane.Text‘的数据,
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cmd貌似是关键字吧...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询