اديت ديتابيس با ديتا گريد

ژولیا

New Member
هدف این کد اینه که وقتی صفحه لود میشه table مورد نظر توی یک datagrid توی صفحه نشون داده میشه و هر ردیف یک ستون edit داره که وقتی کلیک میشه تبدیل میشه به update و cancel..cancel عمل میکنه اما وقتی یک داده رو تغییر میدم و update رو میزنم اینerror میاد .کلا هر بارامتری دوم باشه این errorروميده::(خط 53)[Exception Details: System.Data.SqlClient.SqlException: Prepared statement '(@uu int,@description text,@prize float,@esm ntext,@offer char(1' expects parameter @description, which was not supplied
**************************************************************
code behind:​
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.


InitializeComponent()

Dim myconne As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection("server=localhost;Initial Catalog=tamrin;user id=sa;password=;")


If Not (Page.IsPostBack) Then

Dim ds As DataSet
Dim mycomma As System.Data.SqlClient.SqlDataAdapter = New System.Data.SqlClient.SqlDataAdapter("select * from offers", myconne)
ds = New DataSet
mycomma.Fill(ds, "offers")
mydg.DataSource = ds.Tables("offers").DefaultView
mydg.DataBind()
Response.Write("fgg")

End If
End Sub
***********************************************************************************************
کد:



<script language="vb" runat="server">
Dim myconne As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection("server=localhost;Initial Catalog=Products;user id=sa;password=;")
Sub mydg_edit(Sender AS Object,e AS DataGridCommandEventArgs)
mydg.EditItemIndex=CInt(E.Item.ItemIndex)
bindgrid()
End Sub
Sub mydg_cancel(Sender AS Object,e AS DataGridCommandEventArgs)
mydg.EditItemIndex=-1
bindgrid()
End Sub
Sub mydg_update(Sender AS Object,e AS DataGridCommandEventArgs)
Dim ds AS DataSet
Dim mycomma AS SqlCommand
Dim updatecmd AS String=("update OFFERS set esm=@esm,description=@description,prize=@prize,offer=@offer where uu=@uu")
mycomma=New SqlCommand(updatecmd,myconne)
mycomma.Parameters.Add(New SqlParameter("@uu",SqlDbType.Int,4))
mycomma.Parameters.Add(New SqlParameter("@description",SqlDbType.text,16))
mycomma.Parameters.Add(New SqlParameter("@prize",SqlDBType.Float,8))
mycomma.Parameters.Add(New SqlParameter("@esm",SqlDBType.Ntext,16))
mycomma.Parameters.Add(New SqlParameter("@offer",SqlDbType.Char,10))
mycomma.Parameters("@uu").Value=mydg.Datakeys(CInt(E.Item.ItemIndex))
Dim cols AS String()={"@uu","@description","@prize","@esm","@offer"}
Dim numcols AS Integer=E.Item.Cells.Count
Message.Text=""
Dim I AS Integer
For I=2 to numcols-2
'inke ansi code hast ya na ra check mikonad baraye hameye filead ha ra, hazf kardam mesale 7
Dim currenttextbox AS System.Web.UI.WebControls.TextBox
currenttextbox=E.Item.Cells(I).Controls(0)
Dim colvalue AS String=currenttextbox.Text

IF I<6 AND colvalue=""
Message.Text &="null is not allowed"
End IF
Next
IF Message.Text <> ""

Return
End if
mycomma.Connection.Open()
mycomma.ExecuteNonQuery
Message.Text="record updated"&updatecmd.ToString()
mydg.EditItemIndex=-1

mycomma.Connection.Close()
bindgrid()

End Sub
Sub bindgrid()
Dim ds AS DataSet
Dim mycomma AS SqlDataAdapter
mycomma=New SqlDataAdapter("select * from offers",myconne)
ds=New DataSet()
mycomma.Fill(ds,"offers")
mydg.DataSource=DS.Tables("offers").DefaultView
Mydg.DataBind()
End Sub
</script>
</HEAD>
<​
 
آخرین ویرایش:

جدیدترین ارسال ها

بالا