如何用vs2008在sql serve中建立一个数据库,并在网页中实现对其中一个表的增加和查找

 我来答
琦夏侯岚5o
2011-08-20 · TA获得超过5.9万个赞
知道大有可为答主
回答量:2.8万
采纳率:0%
帮助的人:3913万
展开全部
protected void Button1_Click(object sender, EventArgs e)
{
string UserNameInput = TextBox1.Text;
string UserPasswordInput = TextBox2.Text;
string ReUserPasswordInput = TextBox3.Text;
//Get the content of the TextBox, and assgin.
SqlConnection conn = new SqlConnection
("Data Source=;initial catalog=;user id=sa;pwd =111111;");
//Create a connection to DataBase.
conn.Open();
string insert =
"insert into [Products Information] (ProductsName,ProductsRetailPrice,ProductsDiscountPrice) values(" + "'" + UserNameInput.Trim() + "'" + "如慎," + "'" + UserPasswordInput.Trim() + "'" + "," + "'" + ReUserPasswordInput.Trim() + "'" + ")";
SqlCommand cmd1 = new SqlCommand(insert, conn);
int i = cmd1.ExecuteNonQuery();
if (i != 0)
{
Response.Redirect("/AdminHomepage.aspx");
}
else
{
Response.Write("<script>alert('Do not add!')</script>");
}
conn.Close();

}

protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
//Cancel the operation.
}

public bool EditProduct(int ProductsID,string ProductsName,string ProductsRetailPrice,string ProductsDiscountPrice)
{
bool Edit;
SqlConnection conn = new SqlConnection
("Data Source=;initial catalog=;user id=sa;pwd =111111;");
conn.Open();
string editProducts = "Update [Products Information] set ProductsName=" + "'"皮橡升 + ProductsName.Trim() + "'" + "," + "ProductsRetailPrice=" + "'" + ProductsRetailPrice.Trim() + "'" + "," + "ProductsDiscountPrice=" + "'燃老" + ProductsDiscountPrice.Trim() + "'" + "where ProductsID=" + "'" + ProductsID + "'";
//Edit the content in the Products Information.
SqlCommand cmd1 = new SqlCommand(editProducts, conn);
int i = cmd1.ExecuteNonQuery();
if (i != 0)
{ Edit = true; }
else
{
Edit = false;
}
return Edit;
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;

}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{

int ProductsID1 = Convert.ToInt32(((Label)(GridView1.Rows[e.RowIndex].FindControl("Label1"))).Text);
string ProductsName1 = (GridView1.Rows[e.RowIndex].FindControl("TextBox1") as TextBox).Text;
string ProductsRetailPrice1 = ((GridView1.Rows[e.RowIndex].FindControl("TextBox2") as TextBox).Text);
string ProductsDiscountPrice1 = ((GridView1.Rows[e.RowIndex].FindControl("TextBox3") as TextBox).Text);
bool success=EditProduct(ProductsID1,ProductsName1,ProductsRetailPrice1,ProductsDiscountPrice1);
//Get the content of the TextBox, and assgin.
Response.Redirect("/AdminHomepage.aspx");
}
ljuyx010
2011-08-22 · TA获得超过153个赞
知道小有建树答主
回答量:337
采纳率:0%
帮助的人:77.6万
展开全部
直接在vs2008的界面中点击dataview按钮 直接链接到你数据库的地址 调正属性 就行了
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
商情聚焦
2011-08-20 · TA获得超过145个赞
知道小有建树答主
回答量:323
采纳率:0%
帮助的人:117万
展开全部
直接用那个 dataview啥的 直接链接 调调属性 就ok了。。。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式