数据库再次登录 [英] database logon again

查看:71
本文介绍了数据库再次登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Public Sub rsvrpt()

Dim rpt As new reservationrpt()'你创建的报告。

Dim MyCommand As New SqlCommand()

Dim myDA As New SqlDataAdapter()

Dim myDS As New DataSet2()'你创建的DataSet。

Dim cn As New SqlConnection(ConnectString())



尝试



MyCommand.Connection = cn

MyCommand.CommandText =SELECT * FROM maintable其中irsno =+ irsn

MyCommand.CommandType = CommandType.Text

myDA.SelectCommand = MyCommand

myDA.Fill(myDS ,维护)



myDA.SelectCommand.CommandText =从usertbl中选择全名,其中username ='+ Login.txtuser.Text +'

myDA.Fill(myDS,usertbl)



myDS.EnforceConstraints = False

rpt.SetDat aSource(myDS)

CrystalReportViewer1.ReportSource = rpt

'rpt.PrintOptions.PrinterName =EPSON LX-300 + / II

' rpt.PrintToPrinter(1,False,0,0)

Catch Excep As Exception

MessageBox.Show(Excep.Message,Error,MessageBoxButtons.OK,

MessageBoxIcon.Error)

结束尝试



结束子





美好的一天先生!,我上面的代码正在我的另一个表单上工作。但是当我尝试将它放在我的主表单上时,它总是提示数据库登录在我的第二个表格上没有发生。我应该怎么做我的代码?我已经在我的app.config

Public Sub rsvrpt()
Dim rpt As New reservationrpt() 'The report you created.
Dim MyCommand As New SqlCommand()
Dim myDA As New SqlDataAdapter()
Dim myDS As New DataSet2() 'The DataSet you created.
Dim cn As New SqlConnection(ConnectString())

Try

MyCommand.Connection = cn
MyCommand.CommandText = "SELECT * FROM maintable where irsno=" + irsn
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "maintable")

myDA.SelectCommand.CommandText = "Select fullname from usertbl where username='" + Login.txtuser.Text + "'"
myDA.Fill(myDS, "usertbl")

myDS.EnforceConstraints = False
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
'rpt.PrintOptions.PrinterName = "EPSON LX-300+ /II"
'rpt.PrintToPrinter(1, False, 0, 0)
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try

End Sub


Good day sir!, i have this code above which is working on my other form.but when i try to put it on my main form,it always prompt for a database login which is not happening on my second form.what should i do about my code? i already add this code on my app.config

<startup useLegacyV2RuntimeActivationPolicy="true">

    <supportedRuntime version="v4.0"/>

  </startup>




.

推荐答案

嗨包括数据库登录参数,所以每次执行代码时它都是一个utomatically登录。





Hi kindly include database logon paramets so every time your code is executed it will be automatically logged in.


Try
 
MyCommand.Connection = cn
MyCommand.CommandText = "SELECT * FROM maintable where irsno=" + irsn
MyCommand.CommandType = CommandType.Text
myDA.SelectCommand = MyCommand
myDA.Fill(myDS, "maintable")
 
myDA.SelectCommand.CommandText = "Select fullname from usertbl where username='" + Login.txtuser.Text + "'"
myDA.Fill(myDS, "usertbl")
 
myDS.EnforceConstraints = False

'''''INCLUDE THIS'''''''''''''''''''''''''''''''''''''''''''
rpt.SetDatabaseLogon("database_name", "database_password")

rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource = rpt
'rpt.PrintOptions.PrinterName = "EPSON LX-300+ /II"
'rpt.PrintToPrinter(1, False, 0, 0)
Catch Excep As Exception
MessageBox.Show(Excep.Message, "Error", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try


这篇关于数据库再次登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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