When I try to make another search order the program gets stuck.
I mean I can make one search operation, but then program stops working.
This is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Static m As Integer = 0
If TextBox1.Text = Trim("") Then Exit Sub
If RadioButton4.Checked = True Then
ExactSearch()
ElseIf RadioButton5.Checked = True Then
GeneralSearch()
End If
Conn.Open()
Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
DataAdapter1.Fill(DataSet1, "Table1")
Conn.Close()
TextBox2.DataBindings.Add("Text", DataSet1, "Table1.Name")
TextBox3.DataBindings.Add("Text", DataSet1, "Table1.DatTim")
TextBox4.DataBindings.Add("Text", DataSet1, "Table1.mobile")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "Table1"
'Button1.Enabled = False
If Me.BindingContext(DataSet1, "Table1").Count = 0 Then
MsgBox("No Result, Please Try Again ")
Exit Sub
End If
Button2.Enabled = True
Button3.Enabled = True
End Sub
Public Sub ExactSearch()
If RadioButton1.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE name = '" & TextBox1.Text & "'"
ElseIf RadioButton2.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE DatTim = '" & TextBox1.Text & "'"
ElseIf RadioButton3.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE mobile = '" & TextBox1.Text & "'"
End If
End Sub
Public Sub GeneralSearch()
If RadioButton1.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE name LIKE '%" & TextBox1.Text & "%'"
ElseIf RadioButton2.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE DatTim LIKE '%" & TextBox1.Text & "%'"
ElseIf RadioButton3.Checked = True Then
SQLstr = "SELECT * FROM Table1 WHERE mobile LIKE '%" & TextBox1.Text & "%'"
End If
End Sub
It gets stuck here
TextBox2.DataBindings.Add("Text", DataSet1, "Table1.Name")
Please help.
When
DataAdapter1.Fill(DataSet1, "Table1")
Then
TextBox2.DataBindings.Add("Text", DataSet1.Tables("Table1"), "Name")
Related
The Code is working perfectly and also reflected in the DataGridView which is also sourced in the local database. but when i run it again the new record is not reflected in the local database.
comm = conn.CreateCommand
comm.CommandText = "Insert into tblServices Values('" & txtServiceID.Text & "', '" & txtDescription.Text & "', '" & txtQuantity.Text & "', '" & txtPrice.Text & "', '" & txtRemarks.Text & "', 1)"
comm.ExecuteNonQuery()
I Used a Local DB inside VB .Net. The one that can be found in Server Explorer
enter image description here. the one that can be added as an item as Service-Based Database
Here is the entire code:
Public Class frmServices
Dim isAdding As Boolean
Dim isClosing As Boolean
Dim ServiceID As String
Private Sub frmServices_Load(sender As Object, e As EventArgs) Handles MyBase.Load
UpdateServicesView()
'Display_Data("tblServices", dgvServices)
End Sub
Public Sub setUpTextBox(bcolor As Color, clear As Boolean, enabled As Boolean)
txtDescription.BackColor = bcolor
txtQuantity.BackColor = bcolor
txtPrice.BackColor = bcolor
txtRemarks.BackColor = bcolor
If clear = True Then
txtDescription.Text = ""
txtQuantity.Text = ""
txtPrice.Text = ""
txtRemarks.Text = ""
End If
txtServiceID.Enabled = False
txtDescription.Enabled = enabled
txtQuantity.Enabled = enabled
txtPrice.Enabled = enabled
txtRemarks.Enabled = enabled
End Sub
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim count As Integer
isAdding = True
isClosing = True
btnClose.Text = "&Cancel"
btnAdd.Enabled = False
btnSave.Enabled = True
setUpTextBox(Color.White, True, True)
Connect()
Try
comm = conn.CreateCommand
comm.CommandText = "Select Count(ServiceID) from tblServices"
count = comm.ExecuteScalar
If count > 1000 Then
txtServiceID.Text = "S-0" + count.ToString
ElseIf count > 100 Then
txtServiceID.Text = "S-00" + count.ToString
ElseIf count > 10 Then
txtServiceID.Text = "S-000" + count.ToString
Else
txtServiceID.Text = "S-0000" + count.ToString
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click
If txtDescription.Text <> "" Or txtPrice.Text <> "" Or txtQuantity.Text <> "" Then
Connect()
If isAdding = True Then
comm = conn.CreateCommand
comm.CommandType = CommandType.Text
comm.CommandText = "Insert into tblServices Values('" & txtServiceID.Text & "', '" & txtDescription.Text & "', '" & txtQuantity.Text & "', '" & txtPrice.Text & "', '" & txtRemarks.Text & "', 1)"
comm.ExecuteNonQuery()
MessageBox.Show("Service Record Information had been saved", "Manalese Dental Clinic", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
comm = conn.CreateCommand
comm.CommandType = CommandType.Text
comm.CommandText = "Update tblServices Set serviceDescription = '" & txtDescription.Text & "', quantity = '" & txtQuantity.Text & "', Price = '" & txtPrice.Text & "', Remarks = '" & txtRemarks.Text & "' Where ServiceId= '" & ServiceID & "'"
comm.ExecuteNonQuery()
MessageBox.Show("Service Record Information had been updated", "Manalese Dental Clinic", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
UpdateServicesView()
setUpTextBox(Color.LightGray, True, False)
isClosing = False
isAdding = False
resetButton(Me.btnAdd, Me.btnSave, Me.btnEdit, Me.btnDelete, Me.btnClose)
Else
MessageBox.Show("Please Fiil-out Require Fields", "Manalese Dental Clinic", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub btnEdit_Click(sender As Object, e As EventArgs) Handles btnEdit.Click
isAdding = False
btnSave.Enabled = True
btnSave.Text = "&Update"
btnClose.Text = "Cancel"
btnEdit.Enabled = False
setUpTextBox(Color.White, False, True)
End Sub
Private Sub btnDelete_Click(sender As Object, e As EventArgs) Handles btnDelete.Click
comm = conn.CreateCommand
comm.CommandType = CommandType.Text
comm.CommandText = "Update tblServices Set Delete = 1 Where ServiceID = '" & ServiceID & "'"
comm.ExecuteNonQuery()
MessageBox.Show("Service Record Information had been Deleted", "Manalese Dental Clinic", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
If isClosing = False Then
Me.Close()
Else
resetButton(Me.btnAdd, Me.btnSave, Me.btnEdit, Me.btnDelete, Me.btnClose)
isAdding = False
setUpTextBox(Color.LightGray, True, False)
End If
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As DataGridViewCellEventArgs) Handles dgvServices.CellContentClick
ServiceID = dgvServices.CurrentRow.Cells(0).Value
txtDescription.Text = dgvServices.CurrentRow.Cells(1).Value
txtQuantity.Text = dgvServices.CurrentRow.Cells(2).Value
txtPrice.Text = dgvServices.CurrentRow.Cells(3).Value
txtRemarks.Text = dgvServices.CurrentRow.Cells(4).Value
btnEdit.Enabled = True
btnAdd.Enabled = False
isClosing = True
btnClose.Text = "&Cancel"
btnDelete.Enabled = True
End Sub
Private Sub UpdateServicesView()
Connect()
dgvServices.Rows.Clear()
comm = conn.CreateCommand
comm.CommandText = "Select * from tblServices Where Deleted = 0"
reader = comm.ExecuteReader
Dim row As String()
While reader.Read
row = New String() {reader(0), reader(1), reader(2), reader(3), reader(4)}
dgvServices.Rows.Add(row)
End While
End Sub
Private Sub txtPrice_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtPrice.KeyPress
If txtPrice.Text.Contains(".") And Not Char.IsNumber(e.KeyChar) And Not Asc(e.KeyChar) = 8 Then
e.Handled = True
ElseIf Char.IsNumber(e.KeyChar) = True OrElse Asc(e.KeyChar) = 8 OrElse e.KeyChar = "." Then
e.Handled = False
Else
e.Handled = True
End If
End Sub
Private Sub txtQuantity_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtQuantity.KeyPress
If Char.IsNumber(e.KeyChar) = True OrElse Asc(e.KeyChar) = 8 Then
e.Handled = False
Else
e.Handled = True
End If
'e.Handled = Not Char.IsDigit(e.KeyChar)
End Sub
Private Sub txtPrice_TextChanged(sender As Object, e As EventArgs) Handles txtPrice.TextChanged
End Sub
End Class
Hi I'm just learning how handle SQL statements using vb.net. My problem is how do I update my table using the items in listbox as an identifier.
My SQL query is working.
update tblBillingSched set Status = 'paid'
where BillNum = 'MA5'
Here's the revised code:
Private Sub btnPostAdvancedPayment_Click(sender As Object, e As EventArgs) Handles btnPostAdvancedPayment.Click
Dim connection_string As String = "Data Source=.\sqlexpress;Initial Catalog=CreditAndCollection;Integrated Security=True"
Dim connection As New SqlConnection(connection_string)
connection.Open()
Dim SQLCmd As SqlCommand
Dim sSQL As String = "UPDATE tblBillingSched SET Status = 'Paid' WHERE BillNum = "
If MessageBox.Show("Continue to Save?", " ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
Dim firstTime As Boolean = True
For Each item In lstBillNum.Items
If (item IsNot Nothing AndAlso item.ToString().Trim().Length > 0) Then
If (firstTime) Then
firstTime = False
Else
sSQL = sSQL & " OR BillNum = "
End If
sSQL = sSQL & "'" & item.ToString() & "'"
End If
Next
SQLCmd = New SqlCommand(sSQL, Connection)
SQLCmd.ExecuteNonQuery()
MessageBox.Show("Client Record Successfully Saved!", " ", MessageBoxButtons.OK, MessageBoxIcon.Information)
connection.Close()
SQLCmd.Dispose()
ElseIf DialogResult.Cancel Then
MessageBox.Show("Saving Cancelled!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim dt as date = CDate(DateTime.Today).ToString("MM/dd/yyyy")
Try
Dim cn As New OleDb.OleDbConnection
cn.ConnectionString = GetConnectionStringByName("FD_project.My.MySettings.fixedepoConnectionString")
Dim sSQL As String = "UPDATE fixdeporeg SET approval = 'A', a_user = 'CFO', " & _
"app_date = # " & dt & "# WHERE slno = "
If MessageBox.Show("Continue to Save?", " ", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = DialogResult.OK Then
Dim firstTime As Boolean = True
For x As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
If (firstTime) Then
firstTime = False
Else
sSQL = sSQL & " OR slno = "
End If
'sSQL = sSQL & "'" & item.ToString() & "'"
sSQL = sSQL & CheckedListBox1.CheckedItems(x).item("slno")
Next
Dim SQLCmd As OleDbCommand = New OleDbCommand(sSQL, cn)
MessageBox.Show(sSQL)
cn.Open()
'dt = cmd1.ExecuteScalar()
SQLCmd.ExecuteNonQuery()
cn.Close()
ElseIf DialogResult.Cancel Then
MessageBox.Show("Saving Cancelled!", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
I understand that you are after a loop on these lines:
Dim sSQL As String = "UPDATE tblBillingSched SET Status = 'paid' WHERE BillNum = "
Dim firstTime As Boolean = True
For Each item In lstBillNum.Items
If (item IsNot Nothing AndAlso item.ToString().Trim().Length > 0) Then
If (firstTime) Then
firstTime = False
Else
sSQL = sSQL & " OR BillNum = "
End If
sSQL = sSQL & "'" & item.ToString() & "'"
End If
Next
i have the following code to fill two comboboxes using one dataset:
Private Sub sub_cbo_type_load()
Dim ds As New DataSet
ds = cls.cbo_type()
If ds IsNot Nothing _
AndAlso ds.Tables.Count > 0 _
AndAlso ds.Tables(0).Rows.Count > 0 Then
Me.r_cbo_type.DataSource = ds.Tables(0)
Me.r_cbo_type.DisplayMember = "desc"
Me.r_cbo_type.ValueMember = "code"
Me.r_cbo_type.SelectedIndex = -1
Me.m_cbo_type.DataSource = ds.Tables(0)
Me.m_cbo_type.DisplayMember = "desc"
Me.m_cbo_type.ValueMember = "code"
Me.m_cbo_type.SelectedIndex = -1
End If
End Sub
the problems is: whenever the index is changed in one combobox, it's automatically changed in the other one too.
does anyone know how can i solve this?
thanks for your time.
Try cloning the tables:
Private Function CopyTable(ByVal sourceTable As DataTable) As DataTable
Dim newTable As DataTable = sourceTable.Clone
For Each row As DataRow In sourceTable.Rows
newTable.ImportRow(row)
Next
Return newTable
End Function
Then your data sources would be referencing different sources:
Me.r_cbo_type.DataSource = CopyTable(ds.Tables(0))
Me.m_cbo_type.DataSource = CopyTable(ds.Tables(0))
do like this
Private Sub btn_update1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_update1.Click
If MsgBox("Are you sure to update?" & "", MsgBoxStyle.YesNo, "Confirmation") = MsgBoxResult.Yes = True Then
Dim transmode As String = vbNullString
Dim byair As String = vbNullString
Dim bysea As String = vbNullString
If rb_air.Checked = True Then
transmode = "A"
byair = txt_mserial.Text '.Substring(txt_mserial.TextLength - 4, 4)
bysea = vbNullString
ElseIf rb_sea.Checked = True Then
transmode = "B"
byair = vbNullString
bysea = txt_mserial.Text '.Substring(txt_mserial.TextLength - 4, 4)
End If
Try
If con.State = ConnectionState.Closed Then con.Open()
global_command = New SqlCommand("update ytmi_finished_products set rev_ctrl_no = '" & txt_mrev.Text & "', by_air = '" & byair & "', by_sea = '" & bysea & "', transport_mode = '" & transmode & "' where REPLACE(prod_no, '-', '') +'-'+ ISNULL(CONVERT(varchar(50), prod_sx), '') + prod_lvl = '" & txt_mpart.Text & "' and cast(serial_no as numeric) = '" & txt_mserial.Text & "' and req_box_qty = '" & txt_mqty.Text & "' and remarks is null", con)
global_command.ExecuteNonQuery()
global_command.Dispose()
MsgBox("Successfully Updated!", MsgBoxStyle.Information, "Message")
mclear()
Catch ex As Exception
MsgBox("Trace No 20: System Error or Data Error!" + Chr(13) + ex.Message + Chr(13) + "Please Contact Your System Administrator!", vbInformation, "Message")
End Try
End If
End Sub
I have the following routine (that works) but which is messy to update owing to the hand-typed strings it uses:
Private Sub ListDefaults()
Dim conn As New SqlConnection( _
"server=bas047\AUTODESKVAULT;Database=DWGDetails;Integrated Security=SSPI")
'Dim conn As New SqlConnection( _
'"server=bas047\AUTODESKVAULT;Database=DWGDetails;Integrated Security=SSPI")
Try
'clear columns
If Not Me.DataGridView1.DataSource Is Nothing Then
Me.DataGridView1.Columns.Clear()
Me.DataGridView1.DataSource = Nothing
End If
conn.Open()
Dim cmd As SqlCommand = conn.CreateCommand()
Dim DLcmd As SqlCommand = conn.CreateCommand()
Dim ILcmd As SqlCommand = conn.CreateCommand()
'Dim srctbl As String = String.Empty
If RadioButton1.Checked = True Then 'A3
shtsize = "A3"
cmd.CommandText = "SELECT [AttributeName],[IsDefaultValue],[DefaultValue] FROM " & _
Chr(34) & "DefaultValues(Borders SB-A3_993-5.2(block))" & Chr(34)
srctbl = "DefaultValues(Borders SB-A3_993-5.2(block))"
ElseIf RadioButton2.Checked = True Then 'A2
shtsize = "A2"
cmd.CommandText = "SELECT [AttributeName],[IsDefaultValue],[DefaultValue] FROM " & _
Chr(34) & "DefaultValues(Borders SB-A2_992-5.2(block))" & Chr(34)
srctbl = "DefaultValues(Borders SB-A2_992-5.2(block))"
ElseIf RadioButton3.Checked = True Then 'A1
shtsize = "A1"
cmd.CommandText = "SELECT [AttributeName],[IsDefaultValue],[DefaultValue] FROM " & _
Chr(34) & "DefaultValues(Borders SB-A1_991-5.2(block))" & Chr(34)
srctbl = "DefaultValues(Borders SB-A1_991-5.2(block))"
ElseIf RadioButton4.Checked = True Then 'A0
shtsize = "A0"
cmd.CommandText = "SELECT [AttributeName],[IsDefaultValue],[DefaultValue] FROM " & _
Chr(34) & "DefaultValues(Borders SB-A0_990-5.2(block))" & Chr(34)
srctbl = "DefaultValues(Borders SB-A0_990-5.2(block))"
End If
'Populate datagridview1
da = New SqlDataAdapter(cmd.CommandText, conn.ConnectionString)
ds = New DataSet
da.Fill(ds, srctbl)
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells)
'should enable setting of the date and drawn by entries
'Dim X As Integer
'For X = 0 To DataGridView1.Rows.Count
' If UCase(DataGridView1.Rows(X).Cells(0).Value) = "DRAWN BY" Then
' MessageBox.Show("Found Drawn by!")
' End If
'Next
Catch ex As System.Data.SqlClient.SqlException
MessageBox.Show("There was an error in executing the SQL." & vbLf & "Error Message:" & ex.Message, "SQL")
Finally
'cleanup and reset!
conn.Close()
End Try
End Sub
And I am thinking this is an ideal candidate for Linq. This is what I have so far that seems to work:
Private Sub ListDefaultsMk1()
Try
Using db As New DWGDetailsDataContext
If RadioButton1.Checked = True Then 'A3
shtsize = "A3"
DataGridView1.DataSource =
From c In db.DefaultValues_Borders_SB_A3_993_5_2_block__s()
Select New With {c.AttributeName, c.IsDefaultValue, c.DefaultValue}
ElseIf RadioButton2.Checked = True Then 'A2
shtsize = "A2"
DataGridView1.DataSource =
From c In db.DefaultValues_Borders_SB_A2_992_5_2_block__s()
Select New With {c.AttributeName, c.IsDefaultValue, c.DefaultValue}
ElseIf RadioButton3.Checked = True Then 'A1
shtsize = "A1"
DataGridView1.DataSource =
From c In db.DefaultValues_Borders_SB_A1_991_5_2_block__s()
Select New With {c.AttributeName, c.IsDefaultValue, c.DefaultValue}
ElseIf RadioButton4.Checked = True Then 'A0
shtsize = "A0"
DataGridView1.DataSource =
From c In db.DefaultValues_Borders_SB_A0_990_5_2_block__s()
Select New With {c.AttributeName, c.IsDefaultValue, c.DefaultValue}
End If
End Using
Catch ex As Exception
MessageBox.Show("There was an error in executing the SQL." & vbLf & "Error Message:" & ex.Message, "SQL")
End Try
End Sub
The next step of my program is to take the (edited) values from the datagridview (In the case of the handwritten SQL code, the shared DataSet "ds") and populate another table but I can't figure out how to do that using Linq.
Can anyone offer assistance?
Thanks in advance,
Alex.
EDIT: Here's what I've reduced it to based on the comment
Private Sub ListDefaultsMk1()
Try
Using db As New DWGDetailsDataContext
If RadioButton1.Checked = True Then 'A3
shtsize = "A3"
DataGridView1.DataSource = (From c In db.DefaultValues_Borders_SB_A3_993_5_2_block__s Select c).ToList()
ElseIf RadioButton2.Checked = True Then 'A2
shtsize = "A2"
DataGridView1.DataSource = (From c In db.DefaultValues_Borders_SB_A2_992_5_2_block__s Select c).ToList()
ElseIf RadioButton3.Checked = True Then 'A1
shtsize = "A1"
DataGridView1.DataSource = (From c In db.DefaultValues_Borders_SB_A1_991_5_2_block__s Select c).ToList()
ElseIf RadioButton4.Checked = True Then 'A0
shtsize = "A0"
DataGridView1.DataSource = (From c In db.DefaultValues_Borders_SB_A0_990_5_2_block__s Select c).ToList()
End If
End Using
Catch ex As Exception
MessageBox.Show("There was an error in executing the Linq2SQL Query!" & vbLf & "Error Message:" & ex.Message, "SQL")
End Try
End Sub
Linq2Sql and DataSets are two completely different beasts and the reason you can both use them in a grid is because the grid can consume more types than just dataset.
You could technically pin down the linq query result using, say, ToList() and then bind the List to a grid. Afterwards all edits will be reflected on List which you can transform into other formats as you feel like (you didn't give much information about where the data should go other than its a table, table in dataset (must it be dataset), table in database, etc).
I'm using visual basic 2008 express edition by linq to sql for my database operation such as edit records. I did not use any sql server but I'm just using the built-in sql server within the visual basic 2008 express. I tried to revised the codes, no error in syntax but there's an error at runtime and it pops-up a window message saying its error message. What I want is to edit the records which were retrieved from the database into the text-boxes and when you click the button5 whatever the new value on the text-boxes should replace the previous one.
The Account field is the field in my Table1 in memrec.dbml which I set up for primary key is true and the rest of the fields are false in its primary key.
The code below still found an error when you run the program and it pops-up a window which says:
NotSupportedException was unhandled - Sql server does not handle comparison of NText, Text, Xml, or Image data types.
It highlights a yellow background on the line:
db.SubmitChanges()
These are what I see on each field's property on Table1 in memrec.dbml property window:
Access - Public
Type - String(System.String)
Server Data Type - Text
Auto-Generated Value - False
Auto-Sync - Never
Delay Loaded - False
Inheritance Modifier - (none)
Nullable - True
Read Only - False
Time Stamp - False
Update Check - Never
Primary Key - False ' Except for the Account field.
What do you see as possible error?
Is it in terms of its settings?
Here's my codes:
Private Sub Button5_Click(------------------) Handles Button5.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or _
TextBox4.Text = "" Then
MsgBox("Please Fill It Up Completely", MsgBoxStyle.Exclamation)
Exit Sub
Else
Dim accnt As String
accnt = TextBox1.Text
Dim db As New memrecDataContext()
Dim editrecord = _
From memrec In db.Table1s _
Where memrec.Account.Contains(accnt) _
Select memrec
For Each memrec In editrecord
If memrec.Account = accnt Then
memrec.Account = TextBox1.Text
memrec.Name = TextBox2.Text
memrec.Address = TextBox3.Text
memrec.Gender = TextBox4.Text
db.SubmitChanges()
Exit Sub
End If
Exit For
Next
MsgBox("No Records Match", MsgBoxStyle.Information)
End If
End Sub
Thank you for taking time with me to solve this issue.....
Where memrec.Account.Contains(accnt) _
This code will perform a "like" in your database and such action is not permited on NText and Text field.
Try changing your field type from Text to Varchar(500) (or bigger if you think 500 won't be enough)
or
If you intended to search for a known value, try changing you where to :
Where memrec.Account = accnt
Imports System.Data
Imports System.Data.SqlClient
Public Class frmRpro
Private Sub frmRpro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lock()
End Sub
Private Sub autonum()
Call main()
Con.Open()
Dim UserSelect As SqlCommand
Dim myreader As SqlDataReader
Dim sql As String
Dim sum As Integer
Dim no As Integer
'sql = "select * from packwell_customers where customer_code like '" & (txt1.Text) & "%'"
'sql.Max()
sql = "select max(rcv_reference) from DOrproduct"
UserSelect = New SqlCommand(sql, Con)
myreader = UserSelect.ExecuteReader
If (myreader.Read = True) Then
no = 1
txt1.Text = myreader(0)
sum = txt1.Text + no
txt1.Text = 0 & sum
clear()
End If
Con.Close()
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cnew.Click
If cnew.Text = "New" Then
cnew.Text = "Save"
cedit.Text = "Cancel"
clear()
autonum()
unlock()
cdel.Enabled = False
csearch.Enabled = False
txt1.Enabled = False
'Dim myDate As Date = Now
'txt3.Text = Format(myDate, "MM/dd/yyyy")
ElseIf txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Or txt4.Text = "" Or txt5.Text = "" Or txt6.Text = "" Or txt7.Text = "" Or txt8.Text = "" Or txt9.Text = "" Or txt10.Text = "" Or txt11.Text = "" Or txt12.Text = "" Or txt13.Text = "" Or txt14.Text = "" Or txt15.Text = "" Or txt16.Text = "" Or txt17.Text = "" Or txt18.Text = "" Or txt19.Text = "" Or txt20.Text = "" Or txt21.Text = "" Or txt22.Text = "" Or txt23.Text = "" Or txt24.Text = "" Or txt25.Text = "" Or txt26.Text = "" Then
MsgBox("Incomplete data")
Else
cnew.Text = "Save"
cnew.Text = "New"
cedit.Text = "Update"
save()
clear()
lock()
cdel.Enabled = True
csearch.Enabled = True
End If
txt2.Focus()
End Sub
Private Sub save()
Call main()
Con.Open()
Dim adapter As New SqlDataAdapter
Dim sql As String
sql = "insert into DOrproduct (rcv_reference,customer,expected_date,date_arrived,time_arrived,customer_bol,reference,cust_order,releaseno,carrier,trailerno,issuedto,date_rcv,product,accounting,trader,lot,pkg,supply_rcv,status,opened_by,odate,arrivedby,adate,closeby,cdate) values('" & txt1.Text & "','" & txt2.Text & "', '" & txt3.Text & "', '" & txt4.Text & "', '" & txt5.Text & "', '" & txt6.Text & "', '" & txt7.Text & "', '" & txt8.Text & "', '" & txt9.Text & "', '" & txt10.Text & "', '" & txt11.Text & "', '" & txt12.Text & "', '" & txt13.Text & "', '" & txt14.Text & "', '" & txt15.Text & "', '" & txt16.Text & "', '" & txt17.Text & "', '" & txt18.Text & "', '" & txt19.Text & "', '" & txt20.Text & "', '" & txt21.Text & "', '" & txt22.Text & "', '" & txt23.Text & "', '" & txt24.Text & "', '" & txt25.Text & "', '" & txt26.Text & "')"
Try
adapter.InsertCommand = New SqlCommand(sql, Con)
adapter.InsertCommand.ExecuteNonQuery()
MsgBox("Row inserted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Con.Close()
End Sub
Private Sub clear()
'txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.Text = ""
txt5.Text = ""
txt6.Text = ""
txt7.Text = ""
txt8.Text = ""
txt9.Text = ""
txt10.Text = ""
txt11.Text = ""
txt12.Text = ""
txt13.Text = ""
txt14.Text = ""
txt15.Text = ""
txt16.Text = ""
txt17.Text = ""
txt18.Text = ""
txt19.Text = ""
txt20.Text = ""
txt21.Text = ""
txt22.Text = ""
txt23.Text = ""
txt24.Text = ""
txt25.Text = ""
txt26.Text = ""
End Sub
Private Sub unlock()
txt1.Enabled = True
txt2.Enabled = True
txt3.Enabled = True
txt4.Enabled = True
txt5.Enabled = True
txt6.Enabled = True
txt7.Enabled = True
txt8.Enabled = True
txt9.Enabled = True
txt10.Enabled = True
txt11.Enabled = True
txt12.Enabled = True
txt13.Enabled = True
txt14.Enabled = True
txt15.Enabled = True
txt16.Enabled = True
txt17.Enabled = True
txt18.Enabled = True
txt19.Enabled = True
txt20.Enabled = True
txt21.Enabled = True
txt22.Enabled = True
txt23.Enabled = True
txt24.Enabled = True
txt25.Enabled = True
txt26.Enabled = True
End Sub
Private Sub lock()
txt1.Enabled = False
txt2.Enabled = False
txt3.Enabled = False
txt4.Enabled = False
txt5.Enabled = False
txt6.Enabled = False
txt7.Enabled = False
txt8.Enabled = False
txt9.Enabled = False
txt10.Enabled = False
txt11.Enabled = False
txt12.Enabled = False
txt13.Enabled = False
txt14.Enabled = False
txt15.Enabled = False
txt16.Enabled = False
txt17.Enabled = False
txt18.Enabled = False
txt19.Enabled = False
txt20.Enabled = False
txt21.Enabled = False
txt22.Enabled = False
txt23.Enabled = False
txt24.Enabled = False
txt25.Enabled = False
txt26.Enabled = False
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim frm As New frmRID
frm.Show()
frm.MdiParent = frmMain
Me.Hide()
End Sub
Private Sub locked()
txt1.Enabled = True
txt2.Enabled = True
End Sub
Private Sub unlocked()
txt1.Enabled = False
txt1.Enabled = False
End Sub
Private Sub cedit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cedit.Click
If cedit.Text = "Update" Then
If txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Or txt4.Text = "" Or txt5.Text = "" Or txt6.Text = "" Or txt7.Text = "" Or txt8.Text = "" Or txt9.Text = "" Or txt10.Text = "" Or txt11.Text = "" Or txt12.Text = "" Or txt13.Text = "" Or txt14.Text = "" Or txt15.Text = "" Or txt16.Text = "" Or txt17.Text = "" Or txt18.Text = "" Or txt19.Text = "" Or txt20.Text = "" Or txt21.Text = "" Or txt22.Text = "" Or txt23.Text = "" Or txt24.Text = "" Or txt25.Text = "" Or txt26.Text = "" Then
MsgBox("you have no record to update please click command Search before update")
Else
updatesave()
csearch.Text = "Search"
clear()
lock()
End If
ElseIf cedit.Text = "Cancel" Then
cnew.Text = "New"
cedit.Text = "Update"
lock()
clear()
cdel.Enabled = True
csearch.Enabled = True
End If
End Sub
Private Sub updatesave()
Call main()
Con.Open()
Dim adapter As New SqlDataAdapter
Dim sql As String
sql = "update DOrproduct set rcv_reference ='" & txt1.Text & "', customer='" & txt2.Text & "', expected_date='" & txt3.Text & "', date_arrived='" & txt4.Text & "', time_arrived='" & txt5.Text & "', customer_bol='" & txt6.Text & "', reference='" & txt7.Text & "', cust_order='" & txt8.Text & "', releaseno='" & txt9.Text & "' ,carrier='" & txt10.Text & "' ,trailerno='" & txt11.Text & "' ,issuedto='" & txt12.Text & "' ,date_rcv='" & txt13.Text & "' ,product='" & txt14.Text & "' ,accounting='" & txt15.Text & "' ,trader='" & txt16.Text & "' ,lot='" & txt17.Text & "' ,pkg='" & txt18.Text & "' ,supply_rcv='" & txt19.Text & "' ,status='" & txt20.Text & "' ,opened_by='" & txt21.Text & "' ,odate='" & txt22.Text & "' ,arrivedby='" & txt23.Text & "' ,adate='" & txt24.Text & "' ,closeby='" & txt25.Text & "', cdate='" & txt26.Text & "' where rcv_reference ='" & txt1.Text & "'"
Try
adapter.UpdateCommand = Con.CreateCommand
adapter.UpdateCommand.CommandText = sql
adapter.UpdateCommand.ExecuteNonQuery()
MsgBox("records updated !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Con.Close()
End Sub
Private Sub csearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles csearch.Click
unlock()
If csearch.Text = "Search" Then
csearch.Text = "Cancel"
cnew.Enabled = False
txt1.Focus()
ElseIf csearch.Text = "Cancel" Then
csearch.Text = "Search"
cnew.Enabled = True
clear()
lock()
End If
End Sub
Private Sub cdel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cdel.Click
On Error GoTo err
If cdel.Text = "Delete" Then
If txt1.Text = "" Or txt2.Text = "" Or txt3.Text = "" Or txt4.Text = "" Or txt5.Text = "" Or txt6.Text = "" Or txt7.Text = "" Or txt8.Text = "" Or txt9.Text = "" Or txt10.Text = "" Or txt11.Text = "" Or txt12.Text = "" Or txt13.Text = "" Or txt14.Text = "" Or txt15.Text = "" Or txt16.Text = "" Or txt17.Text = "" Or txt18.Text = "" Or txt19.Text = "" Or txt20.Text = "" Or txt21.Text = "" Or txt22.Text = "" Or txt23.Text = "" Or txt24.Text = "" Or txt25.Text = "" Or txt26.Text = "" Then
MsgBox("you have no record to Delete please click command Search before update")
Else : cdel.Text = "Delete"
Select Case MsgBox("Are you sure You want to Delete this Record", MsgBoxStyle.YesNo)
Case MsgBoxResult.Yes
deleterecord()
csearch.Text = "Search"
clear()
lock()
Case MsgBoxResult.No
GoTo err
End Select
End If
End If
err:
Exit Sub
End Sub
Private Sub deleterecord()
Call main()
Con.Open()
Dim adapter As New SqlDataAdapter
Dim sql As String
sql = "delete DOrproduct where rcv_reference ='" & txt1.Text & "'"
Try
adapter.DeleteCommand = Con.CreateCommand
adapter.DeleteCommand.CommandText = sql
adapter.DeleteCommand.ExecuteNonQuery()
MsgBox("Records deleted !! ")
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Con.Close()
End Sub
Private Sub txt1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt1.TextChanged
searchrcv_reference()
End Sub
Private Sub searchrcv_reference()
Call main()
Con.Open()
Dim cmd As New SqlCommand("SELECT rcv_reference FROM DOrproduct", Con)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "My List") 'list can be any name u want
Dim col As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col.Add(ds.Tables(0).Rows(i)("rcv_reference").ToString())
If txt1.Text = True Then
showsearch()
End If
Next
txt1.AutoCompleteSource = AutoCompleteSource.CustomSource
txt1.AutoCompleteCustomSource = col
txt1.AutoCompleteMode = AutoCompleteMode.Suggest
Con.Close()
End Sub
Private Sub showsearch()
Call main()
Con.Open()
Dim UserSelect As SqlCommand
Dim myreader As SqlDataReader
Dim sql As String
sql = "select * from DOrproduct where rcv_reference like '" & (txt1.Text) & "%'"
UserSelect = New SqlCommand(sql, Con)
myreader = UserSelect.ExecuteReader
If (myreader.Read = True) Then
'txt1.Text = myreader(0)
txt2.Text = myreader(1)
txt3.Text = myreader(2)
txt4.Text = myreader(3)
txt5.Text = myreader(4)
txt6.Text = myreader(5)
txt7.Text = myreader(6)
txt8.Text = myreader(7)
txt9.Text = myreader(8)
txt10.Text = myreader(9)
txt11.Text = myreader(10)
txt12.Text = myreader(11)
txt13.Text = myreader(12)
txt14.Text = myreader(13)
txt15.Text = myreader(14)
txt16.Text = myreader(15)
txt17.Text = myreader(16)
txt18.Text = myreader(17)
txt19.Text = myreader(18)
txt20.Text = myreader(19)
txt21.Text = myreader(20)
txt22.Text = myreader(21)
txt23.Text = myreader(22)
txt24.Text = myreader(23)
txt25.Text = myreader(24)
txt26.Text = myreader(25)
End If
Con.Close()
End Sub
Private Sub txt2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt2.TextChanged
showCustomer()
End Sub
Private Sub showCustomer()
Call main()
Con.Open()
Dim cmd As New SqlCommand("SELECT customer_name,customer_code FROM packwell_customers", Con)
Dim ds As New DataSet
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds, "My List") 'list can be any name u want
Dim col2 As New AutoCompleteStringCollection
Dim i As Integer
For i = 0 To ds.Tables(0).Rows.Count - 1
col2.Add(ds.Tables(0).Rows(i)("customer_code").ToString())
col2.Add(ds.Tables(0).Rows(i)("customer_name").ToString())
Next
txt2.AutoCompleteSource = AutoCompleteSource.CustomSource
txt2.AutoCompleteCustomSource = col2
txt2.AutoCompleteMode = AutoCompleteMode.Suggest
Con.Close()
End Sub
End Class
The code is a little hard to read, but from what I could understand, it should work. You just need to put the SubmitChanges() method invocation outside the for loop.