我不知道如何描述我在找什么,但我可以用我画的图来说明它。多个输入从用户保存在一个数据库的列
这里的第一个是'用户输入',它将在gridview中,它将要求用户输入详细信息。 (文本框)是一个文本框,它旁边的详细信息是一个输入示例。
User Inputs:
Items Quantity Unit Price Total
(textBox)abc (textBox)2 (textBox) 100 (textBox) 200
(textBox)def (textBox)1 (textBox) 150 (textBox) 150
点击保存按钮后(我并没有显示该按钮,对不起),详细信息将在数据库如下面所示的“保存到数据库”进行保存。
Save in Database:
ID Items Quantity UnitPrice Total
10001 Abc , def 2,1 100,150 200,150
而当用户想要显示细节时,细节应该显示在下面的'显示结果'中。
Display Results:
ID:10001
Items Quantity Unit Price Total
Abc 2 100 200
def 1 150 150
我希望这个解释是可以理解的,我在解释和ASP方面都很差。 请帮我在C#或VB中编写代码,因为我无法做到这一点。 非常感谢。
代码示例:
string sql = "INSERT INTO Products(Name, ProductImage, OriginalPrice, DiscountPrice, Descriptions,StockQuantity, Category) VALUES (@Name, @ProdImage, @OriPrice, @DisPrice, @Descrp, @Quantity, @Category)";
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter[] param = new SqlParameter[7];
param[0] = new SqlParameter("@Name", SqlDbType.VarChar,100);
param[1] = new SqlParameter("@ProdImage", SqlDbType.VarChar, 100);
param[2] = new SqlParameter("@OriPrice", SqlDbType.Float);
param[3] = new SqlParameter("@DisPrice", SqlDbType.Float);
param[4] = new SqlParameter("@Descrp", SqlDbType.VarChar,50);
param[5] = new SqlParameter("@Quantity", SqlDbType.Int);
param[6] = new SqlParameter("@Category", SqlDbType.VarChar,50);
param[0].Value = name;
param[1].Value = image;
param[2].Value = OriPrice;
param[3].Value = disPrice;
param[4].Value = description;
param[5].Value = quantity;
param[6].Value = Category;
for (int i = 0; i < param.Length; i++)
{
cmd.Parameters.Add(param[i]);
}
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
当前代码:
private string CreateRow(DataTable data, Int32 index, String ColumnName)
{
String[] quan = data.Rows[0][ColumnName].ToString().Split(',');
if (quan.Length >= index)
return quan[index].ToString();
else
return "";
}
protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("");
string sql = "SELECT * FROM SalesOrder WHERE ID = 10010";
DataSet DataFromDataBase = new DataSet();
SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM SalesOrder WHERE ID = 10010", conn);
adp.Fill(DataFromDataBase);
DataTable TempData = new DataTable();
TempData.Columns.Add("Quantity", typeof(string));
TempData.Columns.Add("UnitPrice", typeof(string));
for (Int32 i = 0; i < 5; i++)
{
DataRow row = TempData.NewRow();
row[0] = CreateRow(DataFromDataBase, i, "Quantity");
row[1] = CreateRow(DataFromDataBase , i, "UnitPrice");
TempData.Rows.Add(row);
}
}
数据,你为什么会存放在此的非规范化格式,当输入和输出都正常化? – 2013-03-27 09:02:05
哪个控件用于显示数据?网格视图,中继器,数据列表还是其他? – 2013-03-27 09:02:07
@peterLang,因为我希望细节处于相同的ID下。 – 2013-03-27 09:05:17