Soy nuevo en vb.net
tengo que insertar datos en la tabla utilizando vb.net por favor, ¿alguien ayudar¿Cómo puedo insertar datos en SQL Server utilizando VBNet
He intentado esto
Aquí Probé Ejemplo de código
tengo esta excepción Column name or number of supplied values does not match table definition.
gracias avanzar
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim strName As String = txtName.Text
Dim strId As String = txtID.Text
Dim strPhone As String = txtPhone.Text
Dim strBranch As String = cmboxBranch.SelectedItem.ToString()
Dim strCourse As String = cmbboxCourse.SelectedItem.ToString()
Dim dblFee As Double = Double.Parse(txtFee.Text)
Dim strCommand As String = "insert into student values('" & strName & "','" & strId & "','" & strPhone & "','" & strBranch & "','" & strCourse & "'," & dblFee & ")"
Dim command As SqlCommand = New SqlCommand(strCommand, connection)
command.CommandType = CommandType.Text
'' MsgBox(strCommand)
connection.Open()
If (command.ExecuteNonQuery().Equals(1)) Then
MsgBox("Information stored in database")
Else
MsgBox("Not stored in database")
End If
End Sub
Debería mostrarnos la _table definition_. Tal vez se haya olvidado de convertir '' IDENTIDAD' la columna de pk con autoincrement. Por cierto, estás abierto para SQL-Injection. Debería usar ['SqlParameters'] (http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter.aspx). –
mi tabla 'defn' es' student (SName, SID, SPhone, SBranch, SCourse, SFee) ' todos son de tipo' varchar' excepto 'fee' (' tarifa es de tipo real') – rangasathish
@rangasathish - eso no es una definición de tabla. Lo más fácil es ir a la mesa usando SQL Server Management Studio (SSMS). Haga clic derecho, elija "Tabla de scripts -> Como crear -> Al portapapeles". Luego * edita * tu pregunta y pega el resultado. Nos mostrará los * tipos de datos * para la tabla, cualquier * constraints *, etc. –