//访问Access数据库
public void insertAccess()
{
//OleDbConnection con = new OleDbConnection(GetAccessPath());
OleDbConnection con = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =D:\\My Documents\\Visual Studio 2005\\WebSites\\WebSiteht\\App_Data\\dbht.mdb");
OleDbCommand com = new OleDbCommand(SQL_INSERT_PRODUCTSTYPEINFO, con);
OleDbParameter[] paramcom = this.getParameterAccess("张正明", 110);
for (int i = 0; i < paramcom.Length; i++)
{
com.Parameters.Add(paramcom[i]);
}
try
{
con.Open();
com.ExecuteNonQuery();
con.Close();
}
catch (Exception ex)
{ ex.ToString(); }
}
//访问SQL数据库
public void insertSQL()
{
SqlConnection con = new SqlConnection("server=(local);database=GM_B225;uid=sa;pwd=sa");
SqlCommand com = new SqlCommand(SQL_INSERT_PRODUCTSTYPEINFO_sql, con);
public void CreateMyOleDbCommand(OleDbConnection connection,
string queryString, OleDbParameter[] parameters)
{
OleDbCommand command = new OleDbCommand(queryString, connection);
command.CommandText =
"SELECT CustomerID, CompanyName FROM Customers WHERE Country = ? AND City = ?";
command.Parameters.Add(parameters);
for (int j=0; j<parameters.Length; j++)
{
command.Parameters.Add(parameters[j]) ;
}
string message = "";
for (int i = 0; i < command.Parameters.Count; i++)
{
message += command.Parameters[i].ToString() + "\n";
}
Console.WriteLine(message);
}