在VB.NET 2010中显示一些错误请帮帮我.... [英] Show some error in VB.NET 2010 please help me....

查看:86
本文介绍了在VB.NET 2010中显示一些错误请帮帮我....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

得到一些错误我不明白什么是实际问题请帮帮我

我想在菜单表格中显示数据

数据表只有一行可用这个公司的银行详细信息在税务发票上打印所以,只需要一个银行。

如果用户输入银行名称然后得到一些错误,我添加行数在存储过程中



并在加载时调用该过程并将ID 1固定在标签上



请帮帮我



0703 2018 - imgbb.com [ ^ ]



我尝试过:



Vb.net

 Public Sub GetBankDetails ()
dt = lblbankid.Text
objcombankdetails.combankid = lblbankid.Text
ds = objcombankdetails.GetComBankDetailsBYId()'change
if ds.Ta bles(0).Rows(0).Item(0)= 1然后
MessageBox.Show(No Bank Name Save ....)
txtcombankname.Focus()
End如果
如果ds.Tables(0).Rows(0).Item(0)= 2则
'MessageBox.Show(成功添加新的HSN ...,,MessageBoxButtons。 OK)
结束如果
'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.Table s(0).Rows(0).Item(combankadd)),,ds.Tables(0).Rows(0).Item(combankadd))

txtcombankname。焦点()

结束子



存储过程

 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 * /
返回
结束
ELSE
BEGIN
从tbl_com_bankdetails中选择combankname,comaccnumber,combranchname,combankadd,combankIFSC,其中combankid = @ combankid
select 2 / * Success * /
END

解决方案

您的存储过程错误!

它应缩短为:

  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





然后,您需要从数据库中获取数据:

 < span class =code-keyword> Dim  sqlConnection1  As   SqlConnection( 您的连接字符串
Dim cmd 作为 SqlCommand
Dim reader As SqlDataReader
DIm dt As DataTable()

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

sqlConnection1.Open()

reader = cmd.ExecuteReader()
' 将数据导入DataTable对象
dt.Load(reader)

' 如果至少有一行填充数据:)
如果 dt.Rows.Count()> = 1 然后
' 这里是你的代码
txtcombankname.Text = dt.Rows( 0 )。Item( combankname
' 代码的其余部分
结束 如果

sqlConnection1.Close()





有关详细信息,请参阅:如何:执行存储过程返回行 [ ^ ]


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 

解决方案

Your stored procedure is wrong!
It should be shorten to:

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:

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[^]


这篇关于在VB.NET 2010中显示一些错误请帮帮我....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆