View: 4287|Reply: 17
|
Tolong..check db null value untuk vb.net
[Copy link]
|
|
salam,
aku dah tension tahap kritikal hampir2 meletop kpala otak dah nih dok cari cara nk check database nyer value sama ada dia null atau tidak. database guna mssql.
buat masa skrg aku dah test smua kat bawah:
1) SqlReader("packout" & i).Equals(DBNull.Value)
2) SqlReader("packout" & i) is DBNull.Value
3) SqlReader("packout" & i).tostring = ""
4) SqlReader("packout" & i).tostring = "NULL"
5) SqlReader("packout" & i).tostring is Nothing
6) SqlReader("packout" & i) is Nothing
7) SqlReader("packout" & i) = Nothing
and semua dia wat dek jer, langsung xdetect kata benda tuh adalah NULL!!!!!
tolong saper2 ada cara lain tak untuk check database null value nih guna vb.net |
|
|
|
|
|
|
|
kenapa nak detect NULL tu?
adakah nak detect rekod ada atau tak ? |
|
|
|
|
|
|
|
yup..nk detect value untuk column dalam db tuh ada isi ke x..ok cmni...skrg nih value dalam database adalah NULL, so nk check NULL value nih dlu sblum proceed untuk process..kalo dia NULL, xdapat nk process.. nih part of coding yg dah wat:- While SqlReader.Read
- While i < 9
- If SqlReader("packout" & i).Equals(DBNull.Value) Then 'part nih yg masalah nih
- checker = "yes"
- Exit While
- Else
- checker = "no"
- End If
- i = i + 1
- End While
- If checker = "yes" Then
- Exit While
- End If
- End While
Copy the Code |
|
|
|
|
|
|
|
cuba tempek sql satement kt sini |
|
|
|
|
|
|
|
Meh aku tempek 1 function trus:- Function checkNULL() As String
- Dim checker As String
- Dim i As Integer
- i = "1"
- checker = "yes"
- Dim myCmd1 As New SqlCommand
- myCmd1.Connection = objConn
- objConn.Open()
- Sql = "Select * from vw_costs"
- myCmd1.CommandText = Sql
- SqlReader = myCmd1.ExecuteReader
- While SqlReader.Read
- While i < 9
- If SqlReader("packout" & i).Equals(DBNull.Value) Then
- checker = "yes"
- Exit While
- Else
- checker = "no"
- End If
- i = i + 1
- End While
- If checker = "yes" Then
- Exit While
- End If
- End While
- objConn.Close()
- Return checker
- End Function
Copy the Code |
|
|
|
|
|
|
|
Post Last Edit by naikAntena at 17-3-2010 09:18
- Dim checker As String
- Dim i As Integer
- dim nilai as string \\ declare nk pegang value dr field
- i = "1"
- checker = "yes"
- Dim myCmd1 As New SqlCommand
- myCmd1.Connection = objConn
- objConn.Open()
- Sql = "Select * from vw_costs where PACKOUT is null"
- myCmd1.CommandText = Sql
- SqlReader = myCmd1.ExecuteReader
- nilai = sqlreader
- While SqlReader.Read
- While i < 9
- If nilai = "" Then \ \ xsure dr segi syntax tapi ktia check kt sini berdasarkan query yg dia run! OK x idea mcm nih
- checker = "yes"
- Exit While
- Else
- checker = "no"
- End If
- i = i + 1
- End While
- If checker = "yes" Then
- Exit While
- End If
- End While
- objConn.Close()
- Return checker
- End Function
Copy the Code
nak tanya sket macam mana korang leh wat dlm point2 kotak putih ar.... nk wat gak... tp x jadi
.:. dah jadi yessss |
|
|
|
|
|
|
|
nak tanya sket macam mana korang leh wat dlm point2 kotak putih ar.... nk wat gak... tp x jadi
naikAntena Post at 17-3-2010 09:00
erm...wktu nk reply tuh...kat barisan yang ada feature bold/alignment/smiley tuh...ada feature bertanda mcm nih <> ...yang feature nih digunakan untuk meletak coding. sekian. mekaceh. |
|
|
|
|
|
|
|
erm...wktu nk reply tuh...kat barisan yang ada feature bold/alignment/smiley tuh...ada feature bertanda mcm nih ...yang feature nih digunakan untuk meletak coding. sekian. mekaceh.
FMKiller Post at 17-3-2010 09:08
Owh thanks tgh edit kt atas.! harap leh verikan sedikit idea |
|
|
|
|
|
|
|
Owh thanks tgh edit kt atas.! harap leh verikan sedikit idea
naikAntena Post at 17-3-2010 09:14
aku dah try idea yg mcm dicadangkn.letak value dekat temporary variable...result dia hampeh...ciput nyer vb.net. nih sample code aku:
'sblum nih aku check 8 column untuk setiap row..kali nih aku hardcode 1 column jer untuk setiap row
- While SqlReader.Read 'loop bila masih ada record dlm table/view tuh
- 'While i < 9 'aku disable yg nih sbb nih digunakn untuk check 8 column
- temp = SqlReader("packout1").ToString 'kat sini aku assign value dari db column packout1 ke temp variable.
- If temp = "" Then 'pastuh aku check temp tuh kosong ke x..
- checker = "yes" 'kalo kosong checker = "yes"
- Exit While 'aku kluar loop, so kalo jumpa jer 1 kosong trus kluar loop then return checker
- Else
- checker = "no" 'kalo ada isi, checker = "no"
- End If
- 'i = i + 1
- 'End While
- 'If checker = "yes" Then
- ' Exit While
- 'End If
- End While
Copy the Code
then bawah nih masa aku nk panggil function checkNULL tuh:
- check = checkNULL()
- If check = "no" Then 'patotnya kalo function atas tuh return yes(maksudnya value tuh xde), dia xkn masuk sini..msalahnya system bongok nih still masuk sini..mangkuk punya asp.net + vb nih...nk check NULL jer pon!!!!!!!!
- updateCost()
- End If
Copy the Code |
|
|
|
|
|
|
|
guna break-point tgk value apa yg dia pass kt sini
temp = SqlReader("packout1").ToString |
|
|
|
|
|
|
|
buat statement utk Select top 1(*) from vw_costs where PACKOUT is null
sistem x dpt nk asign satu nilai utk hantar ke condition |
|
|
|
|
|
|
|
Post Last Edit by FMKiller at 17-3-2010 12:22
aku dah tau apa masalah dia!!!!!!! adoi la..bazir jer masa aku 2 hari... T_T.. aku salah letak nma table....patot ler ada isi dalam column tuh...argh!!! :@
and terima kasih kepada yang mengambil masa untuk tolong aku nih...terutama dekat naikAntena.. |
|
|
|
|
|
|
|
haha...aku lagi rasa nak nanges...mcm nk hentak2 jer monitor nih..isk3..
aku boleh tolong takat yang aku mmpu jer..sma2 la kita bercoding.hehe. |
|
|
|
|
|
|
|
tak pe, tak pe...
setiap usaha tu bukan sia2. pasti ada pelajarannya..
so, lain kali lebih beringat dan berhati2.
tak gitu ?? |
|
|
|
|
|
|
|
adeh! huhuhuhu aku lak siap complite gitu gitu separuh dalam kepala huhuhu...rupanya gitu citernya huhuhu |
|
|
|
|
|
|
|
hahahahahaha aku agak dah.. tu masalah yang selalu jadi.
so pengajarannya kene test statement tu dulu sebelum guna. |
|
|
|
|
|
|
|
if isdbnull(SqlReader("packout" & i)) |
|
|
|
|
|
|
| |
|