0

I can not fill data set. I have a procedure with the same name in my database which I call , and it is not an error in spelling. It successfully connect to the database

(Public Sqlcon As New SqlConnection With {.connectionString = "server=xxx-PC\SQLEXPRESS;database=TEST;Trusted_Connection=True;"} )

This is an example of my code.

Public Function getSelc()

   Dim objDS = New DataSet
   Dim objDA As New SqlDataAdapter

   Dim com As New SqlCommand

   Sqlcon.Close()
   Sqlcon.Open()

   Try

      com = New SqlCommand("EXECUTE regionSelect '" & txtID.EditValue & " ' , ' " & txtRegion.EditValue & "' , '" & txtShortN.EditValue & "', ' " & txtStatus.EditValue & " ' ", Sqlcon)

      objDA.SelectCommand = com
      objDA.Fill(objDS)                         ' => could not find stored procedure.

      GridControl1.DataSource = objDS.Tables(0)  ' this is my goal

      objDA.Dispose()
      com.Dispose()

      Sqlcon.Close()
      MessageBox.Show("The selected data set")

   Catch ex As Exception

      MessageBox.Show(ex.Message)

   End Try

End Function
  • Do you get an error message? it would probably be useful to share it if you do. If you don't get an error then your query may not return any data, so debug it, copy the sql into managemtn studio to see what the result is – Tanner Jul 03 '14 at 13:36
  • 1
    Use `com.CommandType=CommandType.StoredProcedure` and add appropriate parameters. http://stackoverflow.com/a/7542564/284240 – Tim Schmelter Jul 03 '14 at 13:39
  • I got an error message... it could not find stored procedure, and yes the query in sql return data. I also added com.commandType = CommandType.StoredProcedure and same erorr again! I establishes a connection to the database through a windows Authentication....Could this be the reason –  Jul 03 '14 at 14:07

1 Answers1

0

You need to specify the type of command you want to execute.

com.CommandType = CommandType.StoredProcedure

Because you haven't specifically set this, it defaults to type Text. So put this line after the line where you create the SqlCommand object.

More information here.

XN16
  • 5,679
  • 15
  • 48
  • 72
  • 1
    I got an error message... it could not find stored procedure, and yes the query in sql return data. I also added com.commandType = CommandType.StoredProcedure and same erorr again! I establishes a connection to the database through a windows Authentication....Could this be the reason –  Jul 03 '14 at 14:07
  • If you are getting an error saying that it can't find the stored procedure, then make sure the stored procedure's name is correct and that it actually exists in the database you are trying to connect to. Looks like you are connecting fine otherwise you wouldn't get that message. If that doesn't work, change your command to something like `SELECT * FROM Table` where the table is one you know exists and has some data that you can verify when it comes back to the client. – XN16 Jul 03 '14 at 14:15
  • 1
    Okay. Thanks for the advice. The problem created because I had a connection but to the wrong base. I have another question. Is it possible to somehow fill the dataset and transmit to the datagrid, but only columns without data.But not using dataset1.tables (0). clear or similar. SO, only transmit columns without data. For example use code that i drop –  Jul 04 '14 at 11:36