| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2294 人关注过本帖
标题:(求助)从索引 0 处开始,初始化字符串的格式不符合规范
只看楼主 加入收藏
xlt0703
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-13
结帖率:0
收藏
 问题点数:0 回复次数:0 
(求助)从索引 0 处开始,初始化字符串的格式不符合规范
由于我和和另一个人分开弄的,所以可能有点乱,找了一晚上,没弄出来,如果还有别的错误,请各位大神帮忙指出一下,我眼镜已经花了
这是创建数据库部分

public static string strcon = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=test.mdb ";
public static OleDbConnection con = new OleDbConnection(strcon);

string conn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\test.mdb;Persist Security Info=True ";

ADOX.Catalog catalog = new Catalog();
try
{
catalog.Create(conn);
}
catch { }
ADODB.Connection cn = new ADODB.Connection();
cn.Open(conn, null, null, -1);
catalog.ActiveConnection = cn;
ADOX.Table table = new ADOX.Table();
table.Name = "AdPlayList";
ADOX.Column column = new ADOX.Column();
column.ParentCatalog = catalog;
column.Type = ADOX.DataTypeEnum.adInteger; // 必须先设置字段类型
column.Name = "ID";
column.DefinedSize = 0xFF;
column.Properties["AutoIncrement"].Value = true;
table.Columns.Append(column, DataTypeEnum.adInteger, 0);
try
{
catalog.Tables.Append(table);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


这是把存串口接收到的数据存入数据库的函数
public void SaveData()
{
OleDbConnection con = new OleDbConnection(strcon);
con.ConnectionString = "连接字符串";
con.Open();
string sql;
string[] str = new string[5];
sql = "select count(*) as cnt from data ";
OleDbCommand cmd1 = new OleDbCommand(sql, con);
int cnt = int.Parse(cmd1.ExecuteScalar().ToString()) + 1;
str[0] = cnt.ToString();
str[1] = Int32.Parse(tmp[5] + tmp[4], System.Globalization.NumberStyles.HexNumber).ToString();
str[2] = Int32.Parse(tmp[8] + tmp[9], System.Globalization.NumberStyles.HexNumber).ToString();
switch (Int32.Parse(tmp[8] + tmp[9], System.Globalization.NumberStyles.HexNumber))
{
case 3843: str[3] = Int32.Parse(tmp[10] + tmp[11], System.Globalization.NumberStyles.HexNumber) + ":" + Int32.Parse(tmp[12] + tmp[13], System.Globalization.NumberStyles.HexNumber).ToString() + ":" + Int32.Parse(tmp[14] + tmp[15], System.Globalization.NumberStyles.HexNumber).ToString();
flag[1]++;
if (flag[1] == 5)
{
flag[1] = 0;
}
break;
default:
break;
}
str[4] = System.DateTime.Now.Year.ToString() + ":" + System.DateTime.Now.Month.ToString() + ":" + System.DateTime.Now.Day.ToString() + ":" + System.DateTime.Now.Hour.ToString() + ":" + System.DateTime.Now.Minute.ToString() + ":" + System.DateTime.Now.Second.ToString();
sql = "insert into data values" + @"('" + str[0] + "','" + str[1] + "','" + str[2] + "','" + str[3] + "','" + str[4] + "')";
OleDbCommand cmd = new OleDbCommand(sql, con);
cmd.ExecuteNonQuery();
sql = "select nodeid from node where nodeid='" + str[1] + "'";
OleDbCommand cmd5 = new OleDbCommand(sql, con);
OleDbDataReader rd = cmd5.ExecuteReader();
bool j = rd.HasRows;
if (j == false)
{
sql = "insert into node(" + "nodeid" + "," + "status" + ")" + "values('" + str[1] + "','" + "online" + "')";
OleDbCommand cmd2 = new OleDbCommand(sql, con);
cmd2.ExecuteNonQuery();
}
else
{
sql = "update node set status ='online'where nodeid='" + str[1] + "'"; OleDbCommand cmd6 = new OleDbCommand(sql, con);
cmd6.ExecuteNonQuery();
}

DataSet dataSet = new DataSet();
OleDbCommand cmd8 = con.CreateCommand();
= "select sensorid from nsrelation where sensorid='" + Int32.Parse(tmp[8] + tmp[9], System.Globalization.NumberStyles.HexNumber).ToString() + "'";
OleDbDataAdapter adapter = new OleDbDataAdapter(cmd8);
adapter.Fill(dataSet);
if (dataSet.Tables[0].Rows.Count == 0)
{
sql = "insert into nsrelation(" + "nodeid" + "," + "sensorid" + ")" + "values('" + str[1] + "','" + Int32.Parse(tmp[8] + tmp[9], System.Globalization.NumberStyles.HexNumber).ToString() + "')";
OleDbCommand cmd3 = new OleDbCommand(sql, con);
cmd3.ExecuteNonQuery();
}
else
{
sql = "update nsrelation set nodeid ='" + str[1] + "'where sensorid='" + Int32.Parse(tmp[8] + tmp[9], System.Globalization.NumberStyles.HexNumber).ToString() + "'";
OleDbCommand cmd7 = new OleDbCommand(sql, con);
cmd7.ExecuteNonQuery();
}
sql = "update sensor set status ='online'where sensorid='" + str[2] + "'"; OleDbCommand cmd4 = new OleDbCommand(sql, con);
cmd4.ExecuteNonQuery();
}
运行后显示标题的内容。。。
搜索更多相关主题的帖子: static public 字符串 
2013-04-14 21:22
快速回复:(求助)从索引 0 处开始,初始化字符串的格式不符合规范
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021241 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved