PDA

View Full Version : مبتدی: مشکل در جستجوی یک مقدار عددی در ستون مشخص و نمایش نتیجه در تکست باکس



mohammadsaleh
جمعه 13 اردیبهشت 1398, 09:34 صبح
سلام دوستان
در جدولی که مقدار واریز و برداشت شماره حسابهای مشخص وجود داره میخوام مقدار جمع واریز یک شماره حساب رو در یک تکست باکس نمایش بدم
از روشهای زیر هم استفاده کردم جواب نگرفتم

روش اول:

Function GetMandehSep1()
Dim strsql As String
strsql = "SELECT NumHesab, Sum(tblSepordeh.Sepordeh) AS SumVariz, Sum(tblSepordeh.Desepordeh) AS SumBardasht " _
& "From tblSepordeh GROUP BY tblSepordeh.NumHesab " _
& "HAVING NumHesab =" & numHesab.Text & ""




Dim ConnectionString As String = "Data Source=SERVERSGM;Initial Catalog=LoanDB;Integrated Security=True;" ' Data Source=(LocalDB)\v11.0; or Data Source=SERVERSGM;


Using cn As New SqlClient.SqlConnection(ConnectionString)
Using cmd As New SqlClient.SqlCommand(strsql, cn)
cn.Open()
Using reader As SqlClient.SqlDataReader = cmd.ExecuteReader
'This will loop through all returned records
While reader.Read
TextBox1.Text = reader("SumVariz").ToString
'handle returned value before next loop here
End While
End Using
cn.Close()
End Using
End Using




End Function

روش دوم:




Function GetMandehSep()
Dim strsql As String
Dim con As New SqlConnection("Data Source=SERVERSGM;Initial Catalog=LoanDB;Integrated Security=True;")
con.Open()
strsql = "SELECT NumHesab, Sum(tblSepordeh.Sepordeh) AS SumVariz, Sum(tblSepordeh.Desepordeh) AS SumBardasht " _
& "From tblSepordeh GROUP BY tblSepordeh.NumHesab " _
& "HAVING NumHesab =" & numHesab.Text & ""


Dim cmd As New SqlCommand(strsql, con)
TextBox2.Text = cmd.ExecuteScalar().ToString()


con.Close()





End Function

خطایی که نمایش داده میشه اینه
Arithmetic overflow error converting expression to data type int.

با توجه به مبتدی بودن بنده ممنون میشم اساتید راهنمایی بفرماییند بهترین روش برای جستجوی مقادیر در جدول و نمایش نتیجه در لیبل یا تکس باکس چیست.

mehran6764
جمعه 13 اردیبهشت 1398, 10:23 صبح
ببینید این لینک کمکتون می کنه :
http://barnamenevis.org/showthread.php?145534-%D8%AE%D8%B7%D8%A7%DB%8C-Arithmetic-overflow-error-converting-expression-to-data-type-int

mohammadsaleh
جمعه 13 اردیبهشت 1398, 21:30 عصر
سلام . تشکر
مشکلم حل شد
من تصورم بر این بود که جایی از کد رو اشتباه نوشتم