I Want to insert a new row in a SQL table (Insert Sql string with
parameters). The problem is to get one of column values of my datagrid.
That's what I have :
xxxxxxxxxxx FIRST xxxxxxxxxxx
- A column button : " <asp:TemplateColumn HeaderText="Reencaminhar para
Gab. Jur." Itemstyle-VerticalAlign="Top">
<ItemTemplate>
<asp:button id="btnreencaminha"
OnClick="DataGrid_reencaminha" runat="server" Text="Reencaminhar" />
</ItemTemplate>
</asp:TemplateColumn>
XXXXXXXXXXXXXXX Second XXXXXXXXXXXXXXXX
- When the user clicks the button I want to execute the Sub
DataGrid_reencaminha :
Sub DataGrid_reencaminha(sender as Object, e as EventArgs)
Dim DS As DataSet
Dim insertSQL As String = "INSERT into circuito (NUMERO, DESTINO,
DATARECEP, UTILDISTR) " & _
"VALUES (@NUMERO, @DESTINO, @DATARECEP,
@UTILDISTR)"
Dim MyCommand As SqlCommand
MyCommand = New SqlCommand(insertSQL, MyConnection)
MyCommand.Parameters.Add(New SqlParameter("@datarecep",
SqlDbType.DateTime))
MyCommand.Parameters.Add(New SqlParameter("@destino",
SqlDbType.Char, 10))
MyCommand.Parameters.Add(New SqlParameter("@utildistr",
SqlDbType.Char, 10))
MyCommand.Parameters.Add(New SqlParameter("@numero",
SqlDbType.NChar, 10))
dim NumeroTextBox as textbox
NumeroTextBox = e.Item.FindControl("Numero")
Dim ColValue as String = NumeroTextBox.Text
MyCommand.Parameters("@numero").Value = ColValue
MyCommand.Parameters("@utildistr").Value = user.Identity.Name
MyCommand.Parameters("@destino").Value = "GabJur"
MyCommand.Parameters("@datarecep").Value = Now.toshortdatestring()
MyCommand.Connection.Open()
Try
..........
XXXXXXXXXXXXXXXX Third XXXXXXXXXXxx
This Works fine if I give a fixed value in the commnad:
MyCommand.Parameters("@datarecep").Value = 12345
But it doesn't work with the code above : The problem is to retrieve the
Column value .
This is the code for the Column I want to retrieve :
<asp:TemplateColumn HeaderText="Num. Exp." Itemstyle-
VerticalAlign="Top" visible="false">
<ItemTemplate>
<asp:TEXTbOX id="Numero" runat="server"
Text='<%# Container.DataItem("numero") %>'/>
</ItemTemplate>
</asp:TemplateColumn>
XXXXXXXXXXX HELP ME PLEASE XXXXXXXXX
Thanks,
Miuel Simoes
Lisboa
Portugal