Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Parameterized Stored procedure

Parameterized Stored procedure

Scheduled Pinned Locked Moved Visual Basic
databasewpfwcfsecuritycollaboration
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gymnast
    wrote on last edited by
    #1

    I am trying to insert data into the table and teamID is the foreign key in the Participant table. I get an error essentially indicating that String (TeamName) cannot be converted to Integer (TeamID). Here is the code... 'Form_Load event Try 'Create an instance of the data-tier component (GymnasticsMeetData) Dim teamData As New Data.GymnasticsMeetData 'Retrieve the dataset from the data-tier Dim TeamDataSet As GymnasticsDataSet TeamDataSet = teamData.getTeamDataSet 'Set up the binding source Dim tBindingSource As New BindingSource With tBindingSource .DataSource = TeamDataSet .DataMember = "Team" .Sort = "TeamID" End With 'Fill the combobox With Me With .teamComboBox .DataSource = tBindingSource .DisplayMember = "TeamName" .ValueMember = "TeamID" .DataBindings.Add("text", tBindingSource, "TeamName", True, DataSourceUpdateMode.OnValidation) End With End With 'UpdateButton_Click event Dim gymClub As String Try gymClub = teamComboBox.ValueMember '(Tried teamComboBox.Text.. did not work) Model.EnrollClass.GymnastAffiliation = gymClub clubLabel.Visible = True clubLabel.Text = gymClub Catch ex As Exception MessageBox.Show("String to Int: " & ex.Message) End Try 'ADO for data access Dim sqlConnection As SqlConnection = New SqlConnection("Data Source=lp1\sqlexpress;Initial Catalog=Gymnastics;Integrated Security=True") Dim sqlCommand As SqlCommand sqlCommand = New SqlCommand("addGymnast", sqlConnection) sqlCommand.CommandType = CommandType.StoredProcedure sqlConnection.Open() Try Dim sqlParameter3 As SqlParameter = New SqlParameter("@TeamID", SqlDbType.Int) sqlCommand.Parameters.Add(sqlParameter3) sqlParameter3.Value = gymClub '(Tried teamComboBox.ValueMember... did not work) Catch ex As Exception MessageBox.Show("String to Int: " & ex.Message) End Try Dim sqlParameter9 As SqlParameter = New SqlParameter("@RetVal", SqlDbType.Int) sqlCommand.Parameters.Add(sqlParameter9) sqlParameter9.Direction = ParameterDirection.Output If sqlCommand.P

    T 1 Reply Last reply
    0
    • G Gymnast

      I am trying to insert data into the table and teamID is the foreign key in the Participant table. I get an error essentially indicating that String (TeamName) cannot be converted to Integer (TeamID). Here is the code... 'Form_Load event Try 'Create an instance of the data-tier component (GymnasticsMeetData) Dim teamData As New Data.GymnasticsMeetData 'Retrieve the dataset from the data-tier Dim TeamDataSet As GymnasticsDataSet TeamDataSet = teamData.getTeamDataSet 'Set up the binding source Dim tBindingSource As New BindingSource With tBindingSource .DataSource = TeamDataSet .DataMember = "Team" .Sort = "TeamID" End With 'Fill the combobox With Me With .teamComboBox .DataSource = tBindingSource .DisplayMember = "TeamName" .ValueMember = "TeamID" .DataBindings.Add("text", tBindingSource, "TeamName", True, DataSourceUpdateMode.OnValidation) End With End With 'UpdateButton_Click event Dim gymClub As String Try gymClub = teamComboBox.ValueMember '(Tried teamComboBox.Text.. did not work) Model.EnrollClass.GymnastAffiliation = gymClub clubLabel.Visible = True clubLabel.Text = gymClub Catch ex As Exception MessageBox.Show("String to Int: " & ex.Message) End Try 'ADO for data access Dim sqlConnection As SqlConnection = New SqlConnection("Data Source=lp1\sqlexpress;Initial Catalog=Gymnastics;Integrated Security=True") Dim sqlCommand As SqlCommand sqlCommand = New SqlCommand("addGymnast", sqlConnection) sqlCommand.CommandType = CommandType.StoredProcedure sqlConnection.Open() Try Dim sqlParameter3 As SqlParameter = New SqlParameter("@TeamID", SqlDbType.Int) sqlCommand.Parameters.Add(sqlParameter3) sqlParameter3.Value = gymClub '(Tried teamComboBox.ValueMember... did not work) Catch ex As Exception MessageBox.Show("String to Int: " & ex.Message) End Try Dim sqlParameter9 As SqlParameter = New SqlParameter("@RetVal", SqlDbType.Int) sqlCommand.Parameters.Add(sqlParameter9) sqlParameter9.Direction = ParameterDirection.Output If sqlCommand.P

      T Offline
      T Offline
      TurnerRichard
      wrote on last edited by
      #2

      It looks like that the problem is related just to the two types not being the same. I have some code that does the same thing figured I would post and see if it helps. Dim SqlCommand As New System.Data.SqlClient.SqlCommand() ErrorLbl.Text = "" SqlCommand.Parameters.Add("@EventID", SqlDbType.Int) SqlCommand.Parameters("@EventID").Value = EventSelect.SelectedValue.ToString SqlCommand.Connection = SqlConn SqlCommand.CommandText = "[DeleteEvent]" SqlCommand.CommandType = CommandType.StoredProcedure SqlConn.Open() SqlCommand.ExecuteNonQuery() Hope this helps - Richard

      G 2 Replies Last reply
      0
      • T TurnerRichard

        It looks like that the problem is related just to the two types not being the same. I have some code that does the same thing figured I would post and see if it helps. Dim SqlCommand As New System.Data.SqlClient.SqlCommand() ErrorLbl.Text = "" SqlCommand.Parameters.Add("@EventID", SqlDbType.Int) SqlCommand.Parameters("@EventID").Value = EventSelect.SelectedValue.ToString SqlCommand.Connection = SqlConn SqlCommand.CommandText = "[DeleteEvent]" SqlCommand.CommandType = CommandType.StoredProcedure SqlConn.Open() SqlCommand.ExecuteNonQuery() Hope this helps - Richard

        G Offline
        G Offline
        Gymnast
        wrote on last edited by
        #3

        Here is where I get an error message... 'Fill the combobox With Me With .teamComboBox .DataSource = tBindingSource .DisplayMember = "TeamName" .ValueMember = "TeamID" .DataBindings.Add("text", tBindingSource, "TeamName", True, DataSourceUpdateMode.OnValidation) End With End With Not able to convert String ("TeamID") to Int32. It is reading the ValueMember,TeamID as a string, "TeamID". I am not sure if it is OK to use a parent table to populate the combobox, which is what I have done in this case. Team table is the parent of Participant table.

        1 Reply Last reply
        0
        • T TurnerRichard

          It looks like that the problem is related just to the two types not being the same. I have some code that does the same thing figured I would post and see if it helps. Dim SqlCommand As New System.Data.SqlClient.SqlCommand() ErrorLbl.Text = "" SqlCommand.Parameters.Add("@EventID", SqlDbType.Int) SqlCommand.Parameters("@EventID").Value = EventSelect.SelectedValue.ToString SqlCommand.Connection = SqlConn SqlCommand.CommandText = "[DeleteEvent]" SqlCommand.CommandType = CommandType.StoredProcedure SqlConn.Open() SqlCommand.ExecuteNonQuery() Hope this helps - Richard

          G Offline
          G Offline
          Gymnast
          wrote on last edited by
          #4

          EventSelect.SelectedValue.ToString SqlCommand.CommandText = "[DeleteEvent]" Can you explain what EventSelect and [DeleteEvent] mean? Which event are you referring to? Gymnast.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups