|
|
|
ASP.NETจะเก็บข้อมูลใน Listbox มาไว้ในฐานข้อมูล Access Database ยังไงครับ |
|
|
|
|
|
|
|
Code (C#)
string StrConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/db3.mdb;Persist Security Info=False";
OleDbConnection Conn = new OleDbConnection(StrConn);
OleDbCommand cmd = new OleDbCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "insert into datas(ID_name,sum1) Values('" + TextBox1.Text + "','"
+ ??? + "')";
cmd.Connection = Conn;
Conn.Open();
cmd.ExecuteNonQuery();
Conn.Close();
Response.Redirect("Default3.aspx");
|
|
|
|
|
Date :
2011-09-07 13:56:07 |
By :
nitikarn |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แบบ Multi 8รับ
Code (C#)
int i = 0;
TextBox1.Text = "You Selected" + " ";
for (i = 0; i <= ListBox1.Items.Count - 1; i++) {
if (ListBox1.Items(i).Selected) {
TextBox1.Text = TextBox1.Text + ListBox1.Items(i).Text + " ";
}
}
หรือจะ Insert
Code (C#)
OleDbConnection objConn = new OleDbConnection();
OleDbCommand objCmd = new OleDbCommand();
String strConnString,strSQL;
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
Server.MapPath("database/mydatabase.mdb") + ";Jet OLEDB:Database Password=;";
int i = 0;
for (i = 0; i <= ListBox1.Items.Count - 1; i++) {
if (ListBox1.Items(i).Selected) {
strSQL = "INSERT INTO customer (XXX) " +
" VALUES " +
" ('" + ListBox1.Items(i).Text + "')";
objConn.ConnectionString = strConnString;
objConn.Open();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
}
}
this.pnlAdd.Visible = false;
try
{
objCmd.ExecuteNonQuery();
this.lblStatus.Text = "Record Inserted";
this.lblStatus.Visible = true;
}
catch (Exception ex)
{
this.lblStatus.Visible = true;
this.lblStatus.Text = "Record can not insert Error ("+ ex.Message +")";
}
objConn.Close();
objConn = null;
ประมาณนี้ครับ
|
|
|
|
|
Date :
2011-09-08 23:05:28 |
By :
webmaster |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|