Hello anybody
I 'm a beginner programmer and now I have one problems
that is errors " could not find store procedure" in myform

here is my code

Public Sub GRID_STAFF_INFO()
        CONTOSQL()'that is a function for connection to sql server'
        Dim table As New DataTable
        CMD.CommandType = CommandType.StoredProcedure
        CMD.CommandText = "  DTAAGRID_FILL_STAFF"
        CMD.Parameters.Add("@STAFF_ID", SqlDbType.VarChar).Value = Convert.ToString(CboStaffNo.SelectedValue)
        CMD.Parameters.Add("@START_TIME", SqlDbType.DateTime).Value = Convert.ToDateTime(DTPFromDate.Value)
        CMD.Parameters.Add("@END_TIME", SqlDbType.DateTime).Value = Convert.ToDateTime(DTPToDate.Value)
        CMD.Connection = CON
        DATAREADER = CMD.ExecuteReader
        table.Load(DATAREADER)
        dgbStaffInfo.DataSource = table
        dgbStaffInfo.AutoGenerateColumns = True
        DATAREADER.Close()
        CON.Close()
        CON = Nothing
    End Sub

Recommended Answers

All 3 Replies

I see that basically you want to fill a datagrid, there are some cases where is needed to use a datareader, lets say that you want to interact with the values returned from the database and create your own custom table, but if you going to display the data as is, i will fill a dataset or datatable better.

'I see you have two instance one for the SqlConnection "CON" and SqlCommand "CMD"

Dim dt As New DataTable
CMD.CommandType = CommandType.StoredProcedure
CMD.CommandText = "DTAAGRID_FILL_STAFF"
CMD.Connection = CON
CMD.Parameters.Add("@STAFF_ID", SqlDbType.VarChar).Value = Convert.ToString(CboStaffNo.SelectedValue)
CMD.Parameters.Add("@START_TIME", SqlDbType.DateTime).Value = Convert.ToDateTime(DTPFromDate.Value)
CMD.Parameters.Add("@END_TIME", SqlDbType.DateTime).Value = Convert.ToDateTime(DTPToDate.Value)
Dim adapt As New SqlClient.SqlDataAdapter(CMD)
adapt.Fill(dt)
dgbStaffInfo.DataSource = dt

thank you mr.José Bisonó
but I have another error when I retype this code.
error code is " procedure or function DTAAGRID_FILL_STAFF has too many arguments specified."

what can I do?
please help me sir.
that is a assignment for me.
I'm looking forword

That error means that the your sending more parameters to the stored procedure that it supposed to received. just double check how many parameters do you have in your stored procedure.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.