//请帮忙完成代码或修改代码
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class MySql
{
public static string Sql(string app)
{
OleDbConnection Cnn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\MoBin\桌面\1.accdb");
OleDbCommand Cmd = new OleDbCommand(app, Cnn);
Cnn.Open();
OleDbDataReader Dr = Cmd.ExecuteReader();
}
}
private void button1_Click(object sender, EventArgs e)
{
string s = "select * from da";
while() //这里本来是Dr.Read()的,可是我把连接数据库的代码写在类里了,这里因该怎么写.
{
listBox1.Items.Add(MySql.Sql(s,0));
}
}
}
} //把内容读取到LISTBOX1之后,怎么更改数据库字段的内容.(就是修改数据)//如果MYSQL那个类有写错的地方还望高手们更正.
//请给出详细代码
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
class MySql
{
public static string Sql(string app)
{
OleDbConnection Cnn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\MoBin\桌面\1.accdb");
OleDbCommand Cmd = new OleDbCommand(app, Cnn);
Cnn.Open();
OleDbDataReader Dr = Cmd.ExecuteReader();
}
}
private void button1_Click(object sender, EventArgs e)
{
string s = "select * from da";
while() //这里本来是Dr.Read()的,可是我把连接数据库的代码写在类里了,这里因该怎么写.
{
listBox1.Items.Add(MySql.Sql(s,0));
}
}
}
} //把内容读取到LISTBOX1之后,怎么更改数据库字段的内容.(就是修改数据)//如果MYSQL那个类有写错的地方还望高手们更正.
//请给出详细代码
OleDbConnection conn = new OleDbConnection();
string strconn;
strconn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db1.mdb";
conn.ConnectionString = strconn;
try
{
conn.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = conn;
command.CommandText = "SELECT xh AS 学号,xm AS 姓名,cj AS 成绩 FROM table1 ";
OleDbDataReader dr;
dr = command.ExecuteReader();
while (dr.Read())
{
this.listBox1.Items.Add(dr.GetString(0));
this.listBox2.Items.Add(dr.GetString(1));
this.listBox3.Items.Add(dr.GetValue(2).ToString());
}
}
catch (Exception oleE)
{
MessageBox.Show(oleE.Message, "错误提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
finally
{
conn.Close();
}
string strSQL="SELECT * FROM table1";
OleDbConnection MyConnection=new OleDbConnection(StrCon);
OleDbCommand myCommand=new OleDbCommand(strSQL,MyConnection);
OleDbDataReader myDataReader=null;
myCommand.Connection.Open();
myDataReader=myCommand.ExecuteReader();
myDataReader.Read();
Response.Write("dnews="+myDataReader["aa"].ToString());
myCommand.Connection.Close();
{
OleDbConnection connection = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand(strSQL, connection);
try
{
connection.Open();
OleDbDataReader myReader = cmd.ExecuteReader();
return myReader;
}
catch (System.Data.OleDb.OleDbException e)
{
throw new Exception(e.Message);
}
}
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter("select ID, Title, ParentID from [BJProductCategory] where ParentID = @ID", cn);
da.SelectCommand.Parameters.AddWithValue("@ID", Convert.ToInt32(ID));
DataSet ds = new DataSet();
cn.Open();
da.Fill(ds);
cn.Close();
return ds.Tables[0];
比如举个例子:
#region 执行一个查询,返回受影响的行数,结果装载到内置对象中
public int openRset(string Query)
{
int Result;
Fds.Clear();
comm.CommandText=Query;
Result=Ad.Fill(Fds);
return Result;
}
#endregion