日期:2014-05-18 浏览次数:20439 次
System.Data.SqlClient.SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["餐厅点菜ConnectionString"].ConnectionString; conn.Open(); SqlCommand Cmd = new SqlCommand(); Cmd.Connection = conn; conn.Close(); string SqlStr; SqlStr = "Insert into [点餐]([名称])values(@名称)"; Cmd.CommandText = SqlStr; SqlParameter para1 = new SqlParameter("@名称", SqlDbType.VarChar, 50); para1.Value = ListBox1.SelectedValue; Cmd.Parameters.Add(para1); conn.Open(); Cmd.ExecuteNonQuery(); conn.Close(); System.Data.SqlClient.SqlConnection conn1 = new SqlConnection(); conn1.ConnectionString = ConfigurationManager.ConnectionStrings["餐厅点菜ConnectionString"].ConnectionString; conn1.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn1; conn1.Close(); string price = "UPDATE [点餐] SET [价格] = (select 价格 from 菜单 where 名称=(select 名称 from 菜单))"; cmd.CommandText = price; SqlParameter para = new SqlParameter("@价格", SqlDbType.VarChar, 50); para.Value = price; cmd.Parameters.Add(para); conn1.Open(); cmd.ExecuteNonQuery(); conn1.Close();