Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
get some error i don't understand the what is actual problem please help me
I want to show data when i on the form from menu
in the data table only one row available all time this bank details of company which is print on tax invoice so, only one bank required.
if user enter on bank name then getting some error that for i add the row count in stored procedure

and call the procedure in from loading and fix the id 1 in a label

please help me

0703 2018 — imgbb.com[^]

What I have tried:

Vb.net
Public Sub GetBankDetails()
        dt = lblbankid.Text
        objcombankdetails.combankid = lblbankid.Text
        ds = objcombankdetails.GetComBankDetailsBYId() 'change
        If ds.Tables(0).Rows(0).Item(0) = 1 Then
            MessageBox.Show("No Bank Name Save....")
            txtcombankname.Focus()
        End If
        If ds.Tables(0).Rows(0).Item(0) = 2 Then
            ' MessageBox.Show("Successfully add a new HSN...", "", MessageBoxButtons.OK)
        End If
        ' Label1.Text = ds.Tables(0).Rows(0).Item("combankid")
        txtcombankname.Text = If(IsDBNull(ds.Tables(0).Rows(0).Item("combankname")), "", ds.Tables(0).Rows(0).Item("combankname"))
        txtcombankacc.Text = If(IsDBNull(ds.Tables(0).Rows(0).Item("comaccnumber")), "", ds.Tables(0).Rows(0).Item("comaccnumber"))
        txtcombankIFSC.Text = If(IsDBNull(ds.Tables(0).Rows(0).Item("combankIFSC")), "", ds.Tables(0).Rows(0).Item("combankIFSC"))
        txtcombankBranch.Text = If(IsDBNull(ds.Tables(0).Rows(0).Item("combranchname")), "", ds.Tables(0).Rows(0).Item("combranchname"))
        txtcombankAddress.Text = If(IsDBNull(ds.Tables(0).Rows(0).Item("combankadd")), "", ds.Tables(0).Rows(0).Item("combankadd"))

        txtcombankname.Focus()

    End Sub

Stored Procedure
ALTER proc [dbo].[P_GetComBankDetailsBYId]-- 1
@combankid int  
         
As


DECLARE @retVal int
SELECT  @retVal = COUNT(*) FROM tbl_com_bankdetails
--WHERE COLUMN = 'Some Value'

IF (@retVal <1)
BEGIN
 select 1 /*Error*/  
return 
END
ELSE
BEGIN
 select combankname,comaccnumber,combranchname,combankadd,combankIFSC from tbl_com_bankdetails where combankid=@combankid
select 2 /*Success*/  
END 
Posted
Updated 6-Mar-18 22:30pm
Comments
CHill60 7-Mar-18 3:52am    
Surely ds.Tables(0) is returning the result of the query "select combankname, ..." so you are trying to compare a string (combankname) with 1 - which is not allowed.
Use your debugger to examine ds

1 solution

Your stored procedure is wrong!
It should be shorten to:
SQL
ALTER proc [dbo].[P_GetComBankDetailsBYId]
    @combankid int  
AS

SET NOCOUNT ON;

SELECT combankname,comaccnumber,combranchname,combankadd,combankIFSC
FROM tbl_com_bankdetails
WHERE combankid=@combankid

END 


Then, you need to get data from database:
VB.NET
Dim sqlConnection1 As New SqlConnection("Your Connection String")
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
DIm dt As New DataTable()

cmd.CommandText = "StoredProcedureName"
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = sqlConnection1

sqlConnection1.Open()

reader = cmd.ExecuteReader()
'get data into DataTable object
dt.Load(reader)

'populate data if there's at least one row :)
If dt.Rows.Count()>=1 Then
    'here your code
    txtcombankname.Text = dt.Rows(0).Item("combankname")
    'rest of your code
End If

sqlConnection1.Close()


For further details, please see: How to: Execute a Stored Procedure that Returns Rows[^]
 
Share this answer
 
Comments
Jayanta Modak 7-Mar-18 5:11am    
Sir thanks for reply
I used a master page for create the function to connect to the SQL server that for i not used the everytime connection

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900