last day (14 days later) » 

8:44 AM
0
A: How to Check and enter the data from "2 Textboxes" based on the availablity of the data into access from VB .Net

BitAccesserCheck if one field is not empty and then insert, if both empty do nothing. If (Not String.IsNullOrWhiteSpace(CH1.Text)) OR (Not String.IsNullOrWhiteSpace(CHDP1.Text)) Then 'check if at least one field is not empty Dim checkNullCH1 as String Dim checkNullCHDP1 as String If String.IsNullO...

 
It's working bro, but it's inserting 2 rows into access, don't know why it's doing that and also another thing.... bkNmbr.Text will always have some data in it, but like i said in my question, if there's no data in CH1.Text and CHDP1.Text, I don't want to update that record at all (completely ignore it in access).... Given that i still have some data in bkNmbr.Text
 
You don't UPDATE records, you do an INSERT, so every column in a row needs a value (even NULL if no data). Did you remove the chcmd2 part of your code, otherwise it executes twice.
The Ifstatement prevents INSERT if both fields are empty, no matter what .bkNmbr.Text value is.
 
Yes bro, i have removed chcmd2 part of my code and still it executes twice... that is, it's inserting 2 rows with the same data... and also like i said if i have a value in just one textbox (bknmbr.Text) then i'm getting this error bro "No Value given for one or more required parameters" ..... Can u also please check with this issue bro
 
Edit your question and show the new code. Mark the line with the error and add complete error message (maybe you can't assing DBNull.Value to a string, change is to ""). I'm from MS-Access vba which is slightly different (so I would check the textboxes with Len(myTextBox.Text & "") > 0).
 
I figured out what's causing the double entry bro, it's like you have included the "chcmd1.ExecuteNonQuery()" in the IF statement itself and I have "chcmd1.ExecuteNonQuery()" in the Try Statement too. Now I just kept only one, and it's working really great bro... can u please check with bkNmbr.Text issue bro, it's just that even if i don't have any data in either Ch1.Text or CHDP1.Text (both are blank), it should not try to enter the data into access
Hi Bro
 
8:46 AM
Show the new Code! It shouldn't do an insert if both boxes are empty.
 
ya exactly bro... what if two boxes are empty??? this is my question... coz sometimes i really don't have the data in both boxes
juz a minute bro
Imports System.Data.OleDb

Public Class Form1

Dim provider As String
Dim datafile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Dim str As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
datafile = "D:\\Database\samplech.accdb"
connString = provider & datafile
myConnection.ConnectionString = connString
myConnection.Open()
I'm getting error @ this point bro ... "Catch ex As Exception"
and the error message is ... "No value given for one or more required parameters."
 
Delete chcmd1.ExecuteNonQuery() after Try. This executes the insert query ( and no parameters are given because If condition was false), what should only be done in the Ìf`statement.
 
ok bro lemme try it
wowww bro.... you are awesome.... thank u soooo much bro... u helped me a lot... Thanks again
it worked like a charm
I also gave ur answer 1...
 
You're welcome!
Also mark as accepted (then it shows as solved in question list and others don't waste their time, when they want to help you)!
 
9:09 AM
Hi bro u still there bro ???
 
Almost gone! What's up?
 
thank god i got u .... juz one more thing bro
if i use the same code to insert another chcmd2 .... i'm still able to insert the data from chcmd1...??? lemme juz give u the code so that u wud understand
Dim chinsrt2 As String
chinsrt2 = "Insert into bkCharacters([bkch01],[bkch02],[bkch03],[bkCh04]) Values (?,?,?,?)"
Dim chcmd2 As OleDbCommand = New OleDbCommand(chinsrt2, myConnection)

If (Not String.IsNullOrWhiteSpace(CH2.Text)) Or (Not String.IsNullOrWhiteSpace(CHDP2.Text)) Then 'check if at least one field is not empty
Dim checkNullCH2 As String
Dim checkNullCHDP2 As String

If String.IsNullOrWhiteSpace(CH2.Text) Then 'check if field is empty
checkNullCH2 = "" 'replace with "" if you want an empty string instead of NULL
 
I'll have a look.
 
ok bro ... dat wud be great...
 
Where is the prob? This code is in the same button click event? What is your goal?
 
9:19 AM
i have 4 text boxes bro.... namely ch1, chdp1, ch2 and chdp2..... previously i filled the data in only ch1 and chdp1 and written the code accordingly, and with ur help it's working great... now i'm trying to fill in ch2 and chdp2 textboxes also and the output i'm getting in access is 2 rows with data as in ch1 and chdp1 .... i mean it's the same... it's like a double entry.... and yes bro it's same button click event
it's not taking values that i have given in ch2 and chdp 2 and moreover it's inserting the same values from ch1 and chdp1 textboxes
 
strange! Post full code of event not only parts!
 
ok bro
Imports System.Data.OleDb

Public Class Form1

Dim provider As String
Dim datafile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
Dim str As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source="
datafile = "D:\HookABookNow\Database\hookabooknow.accdb"
connString = provider & datafile
myConnection.ConnectionString = connString
myConnection.Open()
i have changed the names of few things bro, hope it won't be a problem ;)
 
Show without changes. Check var values with breakpoints in debuger. Also it's helpfull, if you output var values with debug.print, e.g.: debug.print "CH2.Text Value: " & CH2.Text at the beginning of event.
 
bro, i don't know what happened previously but i tried again now... this time with different values and it's working fine bro.... Thanks bro and sorry for the trouble
thanks for being patient with my code
how can i mark this answer as solved bro ???
 
9:33 AM
ok bro... done... Thumbs up to you
 
Have a nice day, now i'm out (have to earn some money in job). If further probs, I'm back in 8 hours.
 
ok bro.... cool.. i hope u make millions ;)
 

last day (14 days later) »