哪位大哥帮个忙吧。。if (!IsPostBack)
{
string Rid = Request.QueryString["pro_id"];
int num = Convert.ToInt32(Rid);
ConnectionStringSettings settings;//连接字符串
settings = ConfigurationManager.ConnectionStrings["GoodsConnectionString1"];
string connectionString = settings.ConnectionString;
SqlConnection detailconn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader; cmd.CommandText = "select pro_name,pro_price from products where pro_id="+num;
cmd.CommandType = CommandType.Text;
cmd.Connection = detailconn;
detailconn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
string proname = (string)reader["pro_name"];//////proname和proprice好像没
Decimal proprice =(Decimal)reader["pro_price"];////赋值成功
} detailconn.Close();
int ordidd=(int)Session["userID"];
int ordid = Convert.ToInt16(ordidd);
SqlConnection insertconn = new SqlConnection(connectionString);
SqlCommand icmd= new SqlCommand();
icmd.CommandText = "insert into detail" + "(ord_id,pro_id,det_price,det_name,det_num) Values ('" + ordid + "','" + num + "','" + proprice + "','" + proname + "',1)";
icmd.CommandType=CommandType.Text;
icmd.Connection=insertconn;
insertconn.Open();
icmd.ExecuteNonQuery();
insertconn.Close();
{
string Rid = Request.QueryString["pro_id"];
int num = Convert.ToInt32(Rid);
ConnectionStringSettings settings;//连接字符串
settings = ConfigurationManager.ConnectionStrings["GoodsConnectionString1"];
string connectionString = settings.ConnectionString;
SqlConnection detailconn = new SqlConnection(connectionString);
SqlCommand cmd = new SqlCommand();
SqlDataReader reader; cmd.CommandText = "select pro_name,pro_price from products where pro_id="+num;
cmd.CommandType = CommandType.Text;
cmd.Connection = detailconn;
detailconn.Open();
reader = cmd.ExecuteReader();
while (reader.Read())
{
string proname = (string)reader["pro_name"];//////proname和proprice好像没
Decimal proprice =(Decimal)reader["pro_price"];////赋值成功
} detailconn.Close();
int ordidd=(int)Session["userID"];
int ordid = Convert.ToInt16(ordidd);
SqlConnection insertconn = new SqlConnection(connectionString);
SqlCommand icmd= new SqlCommand();
icmd.CommandText = "insert into detail" + "(ord_id,pro_id,det_price,det_name,det_num) Values ('" + ordid + "','" + num + "','" + proprice + "','" + proname + "',1)";
icmd.CommandType=CommandType.Text;
icmd.Connection=insertconn;
insertconn.Open();
icmd.ExecuteNonQuery();
insertconn.Close();
--------------------------------------------------------------------------
用reader.GetString()试试
string proname = null;
Decimal proprice;
while (reader.Read())
{
proname = (string)reader["pro_name"];
proprice =(Decimal)reader["pro_price"];}