如何在表单加载中显示数据库中的递增值 [英] how to show incremented value from databse in form load

查看:51
本文介绍了如何在表单加载中显示数据库中的递增值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里在表单加载事件即时尝试从值sql server数据库ID列中取值并希望

在文本框控件中显示最大值(ID)+1



这里是visual studio,当我开始调试它的开始编译没有任何错误但几秒后它会自动停止调试

帮我解决我的代码中的问题

$ / b


公共类别FrmAdddonor

Dim con作为新的SqlConnection(数据源= Tarun-PC;初始目录= bdsdb;集成安全性=真的)

Private Sub FrmAdddonor_Load(发件人作为对象,e作为EventArgs)处理MyBase.Load



txtdonorID.Enabled = False

Dim number As Integer

con.Open()

Dim Str As String =从tbldonor选择max(ID)+1;

Dim com As New SqlCommand(Str,con)

Dim reader As SqlDataReader = com.ExecuteReader()

如果reader.Read()那么

number = reader(ID)。ToString()

txtdonorID.Text = number

reader.Close()

con.Close( )

结束如果



结束Sub

解决方案

你有一些错误在你的代码中:

-选择语句应该是:从tbldonor选择max(ID)为MAX

-然后将Dim temp作为整数; temp = DirectCast(reader(MAX),Integer)+ 1;

-end finally:txtdonorID.Text = temp.ToString();


< pre lang =vb> 公共 功能 maxuse() as integer
con.Open()
sql =& quot; select IIF(ISNULL(MAX(sms_count)),来自sms_master& quot;的 0 ,MAX(sms_count))
Com = OleDb.OleDbCommand(sql,con)
maxuse = Com.ExecuteScalar()
&#39; If _maxno =& quot;& amp; H0& quot; 然后
&#39; _maxno = 0
&#39;结束如果
Com.ExecuteNonQuery( )
Com.Dispose()
con.Close()
结束 Sub < / pre >





 私人  Sub  Form1_Load( ByVal  sender  As   Object  ByVal  e  As  System.EventArgs)句柄  .Load 
textbox1.text = maxuse()+ 1
结束 Sub


Here in form load event i m trying to take value form sql server database ID column and want to
display max(ID)+1 in textbox control

here in visual studio when i start debug its start compiling without any error but after few seconds it automatically stop debugging
help me whats the issue in my code


Public Class FrmAdddonor
Dim con As New SqlConnection(Data Source=Tarun-PC;Initial Catalog=bdsdb;Integrated Security=True)
Private Sub FrmAdddonor_Load(sender As Object, e As EventArgs) Handles MyBase.Load

txtdonorID.Enabled = False
Dim number As Integer
con.Open()
Dim Str As String =select max(ID)+1 from tbldonor;
Dim com As New SqlCommand(Str, con)
Dim reader As SqlDataReader = com.ExecuteReader()
If reader.Read() Then
number = reader("ID").ToString()
txtdonorID.Text = number
reader.Close()
con.Close()
End If

End Sub

解决方案

You have some errors in your code:
-the select statement should be: "select max(ID) as MAX from tbldonor"
-then Dim temp as integer; temp = DirectCast(reader("MAX"), Integer) + 1;
-end finally: txtdonorID.Text = temp.ToString();


Public Function maxuse() as integer
        con.Open()
        sql = &quot;select IIF(ISNULL(MAX(sms_count)), 0, MAX(sms_count))  from sms_master&quot;
        Com = New OleDb.OleDbCommand(sql, con)
        maxuse = Com.ExecuteScalar()
        &#39;If _maxno = &quot;&amp;H0&quot; Then
        &#39;    _maxno = 0
        &#39;End If
        Com.ExecuteNonQuery()
        Com.Dispose()
        con.Close()
    End Sub</pre>



Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       textbox1.text = maxuse() + 1
   End Sub


这篇关于如何在表单加载中显示数据库中的递增值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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