C#中如何将以关键字搜索access的数据放置listview中?
privatevoidchaxunbutton_Click(objectsender,EventArgse){OleDbConnectioncnn1=newOleDbCo...
private void chaxunbutton_Click(object sender, EventArgs e) { OleDbConnection cnn1 = new OleDbConnection(); cnn1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\C#数据库建立\数据库\数据库\bin\Debug\mdb.mdb"; cnn1.Open(); OleDbCommand cmd = new OleDbCommand("select * from" + guanjianzitextBox.Text.Trim(),cnn1); OleDbDataReader sdr = cmd.ExecuteReader();
请高手指教 展开
请高手指教 展开
1个回答
展开全部
connectString = "Access数据库连接引擎字符串";
/// <summary>
/// 执行sql语句
/// </summary>
/// <param name="cmdString">查询,更新,删除语句</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool ExecuteQuery(string cmdString)
{
MsSql();
SqlConnection conn = new SqlConnection(connectString);
SqlCommand cmd = new SqlCommand(cmdString, conn);
cmd.CommandText = cmdString;
try
{
conn.Open();
if (cmd.ExecuteNonQuery() > 0)
{
conn.Close();
return true;
}
else
{
return false;
}
}
catch (SqlException Sqlex)
{
Console.WriteLine(Sqlex.Message);
return false;
}
}
/// <summary>
/// 执行sql语句
/// </summary>
/// <param name="cmdString">查询,更新,删除语句</param>
/// <returns>成功返回true,失败返回false</returns>
public static bool ExecuteQuery(string cmdString)
{
MsSql();
SqlConnection conn = new SqlConnection(connectString);
SqlCommand cmd = new SqlCommand(cmdString, conn);
cmd.CommandText = cmdString;
try
{
conn.Open();
if (cmd.ExecuteNonQuery() > 0)
{
conn.Close();
return true;
}
else
{
return false;
}
}
catch (SqlException Sqlex)
{
Console.WriteLine(Sqlex.Message);
return false;
}
}
追问
这个是C语言的吧?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询