我从excel中导入了些数据到数据库中,但是不知道怎么提示数据有重复。
只限一列的数据。
我写了个程序进行判断,但是总是不能实现,请大神帮帮忙!
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select ass_catid from assets"; //获取数据库内catid的内容
string d=comm.CommandText ;
com.Parameters["@固定资产类别ID"].Value = dt.Rows[i][j]; j++;
//对固定资产编号的判断
if (c != 11)
{
MessageBox.Show("数据长度错误,请仔细检查第" + r + "行" + 2 + "列!");
conn.Close();
}
else
{
if (dt.Rows [i][j].ToString ().Contains(d))
{
MessageBox.Show("与数据库数据有重复,请仔细检查第" + r + "行" + 2 + "列!");
conn.Close();
}
else
{
com.Parameters["@固定资产编号"].Value = dt.Rows[i][j];
}
}
c#excel数据库
只限一列的数据。
我写了个程序进行判断,但是总是不能实现,请大神帮帮忙!
SqlCommand comm = conn.CreateCommand();
comm.CommandText = "select ass_catid from assets"; //获取数据库内catid的内容
string d=comm.CommandText ;
com.Parameters["@固定资产类别ID"].Value = dt.Rows[i][j]; j++;
//对固定资产编号的判断
if (c != 11)
{
MessageBox.Show("数据长度错误,请仔细检查第" + r + "行" + 2 + "列!");
conn.Close();
}
else
{
if (dt.Rows [i][j].ToString ().Contains(d))
{
MessageBox.Show("与数据库数据有重复,请仔细检查第" + r + "行" + 2 + "列!");
conn.Close();
}
else
{
com.Parameters["@固定资产编号"].Value = dt.Rows[i][j];
}
}
c#excel数据库
DataRow[] existsRow = DataTable.Select(string.Format("列='{0}'"));
if (existsRow != null && existsRow.Length > 0)
{
// 存在
}
d是你的sql语句啊。你这判断包含sql语句吗?
d不是你想要的数据正确读取数据方式之一为:
con.Open();
OleDbCommand command = new OleDbCommand(SqlString, con);
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
string data = reader.GetString(0);
}
这个data才是你想要的数据值。你得再看看ado.net!