I have a datagrid and need a button that duplicates the active row and copies it into a new line. Since i am very new with vb.net i need help with it. I am trying it with the following code:
Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click
Dim conn As New SqlConnection("Data Source=xxx\SQLEXPRESS;Initial Catalog=DB;Integrated Security=TRUE")
Dim insert_cmd As SqlCommand = New SqlCommand("dbo.Table_Insert", conn)
insert_cmd.CommandType = CommandType.StoredProcedure
With Table1_SelectDataGridView.CurrentRow
insert_cmd.Parameters.AddWithValue("@Name", .Cells("Name").Value)
insert_cmd.Parameters.AddWithValue("@Age", .Cells("Age").Value)
End With
conn.Close()
End Sub
combind with the stored procedure
STORED PROCEDURE [dbo].[Table_Insert]
@Name varchar(20)
@FeierT_ID int
AS
BEGIN
SET NOCOUNT ON
INSERT INTO dbo.table1
(
Name,
Age
)
VALUES
(
@Name,
@Age
)
END
When i try to run it in visual studio i get the error: 'Column "Name" cannot be found.' Even thou the table column name is "Name" and "Age" btw. "Age" cannnot be found too. Maybe this is the wrong approach at all. Can anybody tell me what is wrong here?