在ASP.NET中,怎么把DropDownList的内容添加到Access数据库中呢。急用!
2个回答
2013-06-10
展开全部
首先你得获得DropDownList的余棚SelectedValue的值,而衫虚不是SelectedText,竖塌则然后组织SQL语句插入即可了。
2013-06-10
展开全部
try
{
myConn.Open();
DataSet ds = new DataSet();
da = new SqlDataAdapter("Select * from Passenger", myConn);
da.Fill(ds, "Passenger");
da.InsertCommand = myConn.CreateCommand();
da.InsertCommand.CommandText = "insert INTO Passenger values('" + this.txtFlightCode.Text + "','" + this.txtPassPort.Text + "','" +
this.txtName.Text + "','" + this.txtSeatNo.Text + "','" + this.cboSex.SelectedItem.ToString() + "','" + Convert.ToInt16(this.txtAge.Text )+ "')";
DataTable dt = new DataTable();
ds.Tables.Add(dt);
DataRow dr = ds.Tables[0].NewRow();
dr["FlightCode"] = this.txtFlightCode.Text;
dr["PassPortNo"] = this.txtPassPort.Text;
dr["Name"] = this.txtName.Text;
dr["SeatNo"漏数] = this.txtSeatNo.Text;
dr["Sex"] = this.cboSex.SelectedValue; ///////你要的是这段芹困代码
dr["Age"] = this.txtAge.Text;
ds.Tables[0].Rows.Add(dr);
da.Update(ds, "Passenger");
Application.DoEvents();
MessageBox.Show("信息成功添加!");
ClearTextMothed();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConn.Close();
}
往数据库中添加的方法很返首首多,这里给你一种
{
myConn.Open();
DataSet ds = new DataSet();
da = new SqlDataAdapter("Select * from Passenger", myConn);
da.Fill(ds, "Passenger");
da.InsertCommand = myConn.CreateCommand();
da.InsertCommand.CommandText = "insert INTO Passenger values('" + this.txtFlightCode.Text + "','" + this.txtPassPort.Text + "','" +
this.txtName.Text + "','" + this.txtSeatNo.Text + "','" + this.cboSex.SelectedItem.ToString() + "','" + Convert.ToInt16(this.txtAge.Text )+ "')";
DataTable dt = new DataTable();
ds.Tables.Add(dt);
DataRow dr = ds.Tables[0].NewRow();
dr["FlightCode"] = this.txtFlightCode.Text;
dr["PassPortNo"] = this.txtPassPort.Text;
dr["Name"] = this.txtName.Text;
dr["SeatNo"漏数] = this.txtSeatNo.Text;
dr["Sex"] = this.cboSex.SelectedValue; ///////你要的是这段芹困代码
dr["Age"] = this.txtAge.Text;
ds.Tables[0].Rows.Add(dr);
da.Update(ds, "Passenger");
Application.DoEvents();
MessageBox.Show("信息成功添加!");
ClearTextMothed();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
myConn.Close();
}
往数据库中添加的方法很返首首多,这里给你一种
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询