Click here to Skip to main content
16,011,974 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying this but in here i retrive 0 ..

What I have tried:

Public Function TotalYarnBalance_ByNtl_no(ByVal objModel) As Double

Dim sql As String = " select (isnull(sum(rec_frm_suppl_qty),0) +isnull(sum(ret_frm_knit_qty),0)+isnull(sum(ret_frm_subcont_qty),0)+isnull(sum(loan_frm_party),0))-((isnull(sum(iss_to_knitt_qty),0))+isnull(sum(iss_to_subcont_qty),0)+isnull(sum(ret_to_suppl_qty),0)+isnull(sum(loan_to_party),0)+sum(isnull(Sale,0))) as Balance from trans_yarn where ntl_no='" + objModel.ntl_order + "' and yarn_count='" + objModel.yarn_count + "' and yarn_type='" + objModel.yarn_type + "' and brand='" + objModel.brand + "' and lot_no ='" + objModel.lot_no + "' "

Dim dt_type As DataTable
Dim i As Double
dt_type = New DataTable("ViewYarnBalance")
da = New SqlDataAdapter(sql, conn)
conn.Open()
da.Fill(dt_type)
conn.Close()

Return i = dt_type.Rows(0)(0)

End Function
Posted
Updated 15-May-16 5:59am
Comments
turjoy 15-May-16 10:41am    
when this query execute datatable holds the value with single row..i want to return this value as a integer

Your approach is wrong from the very beginning. The query composed by concatenation with strings taken from UI. Not only repeated string concatenation is inefficient (because strings are immutable; do I have to explain why it makes repeated concatenation bad?), but there is way more important issue: it opens the doors to a well-known exploit called SQL injection.

This is how it works: http://xkcd.com/327.

Are you getting the idea? The string taken from a control can be anything, including… a fragment of SQL code.

What to do? Just read about this problem and the main remedy: parametrized statements: http://en.wikipedia.org/wiki/SQL_injection.

With ADO.NET, use this: http://msdn.microsoft.com/en-us/library/ff648339.aspx.

Please see my past answers for some more detail:
EROR IN UPATE in com.ExecuteNonQuery();,
hi name is not displaying in name?.

—SA
 
Share this answer
 
Comments
turjoy 15-May-16 12:23pm    
solution plz...
Sergey Alexandrovich Kryukov 15-May-16 16:53pm    
Why? First fix your major problem. Before you do it, solutions make no sense.
—SA
Firstly, stop doing it like that!
Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead:
VB
Using con As New SqlConnection(strConnect)
	con.Open()
	Using da As New SqlDataAdapter("SELECT MyColumn1, MyColumn2 FROM myTable WHERE mySearchColumn = @SEARCH", con)
		da.SelectCommand.Parameters.AddWithValue("@SEARCH", myTextBox.Text)
		Dim dt As New DataTable()
		da.Fill(dt)
		...
	End Using
End Using

Second, that is stuffed full of SUM operations, which will return null is there is any one null value in your column - so any single value of null will cause your sum to be zero.
Look at your data!
 
Share this answer
 

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