You can force your delete/refresh by making the delete form modal and creating a sub procedure that will refresh the data in the parent form.
Begginnerdev 256 Junior Poster
You can force your delete/refresh by making the delete form modal and creating a sub procedure that will refresh the data in the parent form.
Ok,try this.
This should work fine with SQL Server 2008
'Be sure to import System.Data.OleDB
Dim constr As String = "Provider=SQLOLEDB;Server=BRMS-SERVER;Database=CavsuDB;Integrated Security=SSPI"
Dim sstr As String = "SELECT username,password,category FROM tbl_user WHERE username='" & txtUser.Text & " AND password='" & txtPass.Text & "'"
Dim con As New OleDbConnection(constr)
Dim cmd As New OleDbCommand(sstr, con)
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Try
con.Open()
'Set the string to the data adapter
da.SelectCommand = cmd
da.Fill(ds, "GetData")
dt = ds.Tables("GetData")
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
Main.Show()
Me.Hide()
If chkAdmin.Checked = True Then
cmd.CommandText = "SELECT username,password FROM tbl_user WHERE categor='Admin'"
da.SelectCommand = cmd
da.Fill(ds, ("adminUsers"))
dt.Clear()
dt = ds.Tables("adminUsers")
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
Main.AddUserToolStripMenuItem.Enabled = True
Main.DocumentToolStripMenuItem.Enabled = True
Main.SubjectsToolStripMenuItem.Enabled = True
Main.FacultyToolStripMenuItem.Enabled = True
Main.DepartmentToolStripMenuItem.Enabled = True
Else
MsgBox("There was a problem retrieving the admin users.", MsgBoxStyle.OkOnly)
End If
Else
MsgBox("Admin table is empty.", MsgBoxStyle.OkOnly)
End If
ElseIf chkAdmin.Checked = False Then
cmd.CommandText = "SELECT username,password FROM tbl_user WHERE category='user'"
da.SelectCommand = cmd
da.Fill(ds, ("Users"))
dt.Clear()
dt = ds.Tables("Users")
If dt IsNot Nothing Then
If dt.Rows.Count > 0 Then
Main.AddUserToolStripMenuItem.Enabled = False
Main.DocumentToolStripMenuItem.Enabled = True
Main.SubjectsToolStripMenuItem.Enabled = False
Main.FacultyToolStripMenuItem.Enabled = False
Main.DepartmentToolStripMenuItem.Enabled = False
Else
MsgBox("There was a problem retrieving the users.", MsgBoxStyle.OkOnly)
End If
Else
MsgBox("User table is empty.", MsgBoxStyle.OkOnly)
End If
End If
Else
MsgBox("**USER NOT FOUND**", MsgBoxStyle.OkOnly)
End If
Else
MsgBox("Data table is empty.", MsgBoxStyle.OkOnly)
End If …
You can add a color dialog to your project, and pull the color from that.
A color dialog holds a custom color picker.
As for the scanning, if you are looping through the whole width/height of the screen it will take a long time. The only other way to fix other than the stepping will be to reduce your resolution.
Place the code in a try catch block
Try
'Your code here
Catch ex As Exception
MsgBox(ex.stacktrace.Tostring)
End Try
This will show the exact line that is throwing the error.
Or, alternately. Test each value before performing the action.
If fontSelection.Text <> "" AND Document.SelectionFont.Size ISNOT Nothing AND Document.SelectionFont.Style ISNOT Nothing Then
End If
You can get rid of the has rows, and try:
If myData IsNot Nothing Then
Do While myData.Read
'Place your code here.
'Use GetValue instead of .toString
Loop
Else
MsgBox("Empty Reader")
End IF
I have just one question though.
Is a color dialog out of the picture for your program?
If not, it would make your life SO much easier.
Other than that, what is the height of BMP?
Yep, or dispose after using. That might cause an exception though.
Is SQL client required? If not, I can try to rewriting using an OLEDB client, which I am more famillar with. But this will require you to test it due to your database being local.
If the variable creation is in the loop, you are not disposing the bitmap before trying to create another with the same name.
Sorry, I typed it on the fly.
I forgot about the new Point.
Try this instead.
'For new Y position.
Button1.Location = New Point(Button1.Location.X, Me.Width - 30)
'For new X position
Button1.Location = new Point(Me.hieght - 100, Button1.Location.Y)
The ancor and dock methods might not always work.
That's when I resort the the following method:
'You will have to play with this to get everything right.
'This will automaticly move when the user resizes the window too.
Button1.Location.Y = Me.Width - 30
'You can do the same for the X location.
Button1.Location.X = Me.Height - 10
One easy way to do this would to be pre-query the database with the number that the user is wanting to insert. If the number doesn't exist, then allow them to alter, if it does, prompt them.
This will safeguard from those nasty error messages.
You can not alter autonumbers from queries. They are fixed values.
Change the column to integer.
That should fix your problem, but you can't have two matching numbers.
Is your code wrapped in a loop somewhere?
Can you please post a larger portion of the code so we can analyze it?
Is po_number an autonumber? Just curious.
Do you have loop in your code?
Are you wanting to convert to ASP with VB.net or ASP with C#?
There are two different code languages that drive ASP.net.
Check your database to make sure that the data type is set to date time.
If that is not the case, if you are using a string, parse as a date then pass into the string.
You can use Cdate to do this.
Create a datatable:
'Where table name is the table in the db.
Dim dt As DataTable = ds.Tables("tablename")
Dim newRow As DataRow
'Setting up the table for the data
newRow = dt.NewRow()
'You should replace "column1" and "column2" with the column name in your db.
newRow("column1") = TextBox1.Text
newRow("column2") = TextBox2.Text
dt.Rows.Add(newRow)
'Updating db
da.Update(ds, "tablename")
Then fill the listbox.
Then loop through and check between the values. If the value matches column one, populate the text box from column two.
As reverend stated. It is much easier to create a settings variables such as ServerIP that holds the value from the server ip text box.
That way, on form_exit you can call:
with My.Settings
.ServerIP = txtServerIP.text
.Save
end with
That way you can call it on the next form load, or even call it without needing to pull the values from a text box.
On form load.
with My.Settings
txtServerIP = .ServerIP
end with
Did you try removing the second
WebBrowser1.ScriptErrorsSuppressed = True
And...
For abc = Cint(TextBox5.Text) To Cint(TextBox6.Text) Step 1
Have you tried the .ToString() function?
Example...
TxtRate.Text = dt.Rows(0).Item(1).ToString
I am sorry......
I meant.....
TxtRate.Text = dt.Rows(0).Item(1)
You can try loading the form, without getting the id.
When the user clicks "Save" you will retrieve the id then save.
That way you can prevent what adam_k is talking about.
The only way to receive the same key would be if they both press the buttons at the same time.
You will want to create a data table form the database.
Then you will use the selected index of the combobox to pull from the datatable.
Example...
Select Case cbMenu.SelectedItem
Case 1
TxtRate.Text = dt.Rows(0).Column(1)
......
This will get the value stored in the second column of the corrosponding table row.
Assuming the value is in the second column of the same table.
You will need to create table with an integer field with a default of 0.
On form_load you will want to pull the value from the database and add 1 to it.
On form_close you will want to save that value back to the database.
You can use my previous post here for the connection example.
You will do something like this:
'In the form load event.
sqlcmd = "SELECT curnum FROM table"
cmd = new OleDBCommand(sqlcmd,con)
'In the form close event.
sqlcmd = "UPDATE table SET curnum ='" & txtStudentID.text & "'"
cmd = new OleDBCommand(sqlcmd,con)
You can try:
'sqls is a string
'cmd is a command builder
sqls = "SELECT * FROM employees WHERE id = '" & textbox1.text & "'"
cmd = New CommandBuilder(sqls,connection)
If cmd.ExecuteNonQuery = False Then
MsgBox("ID not found")
End If
Have you tried:
If cmd.ExecuteNonQuery() = False Then
'Your code here
End If
The code above creates a structure, in the form of a class, then passes the string information into the class. It then builds the string and assigns the value to your settings with what ever string name you want it to be.
Then it saves.
To use this, build the class by using the Project > Add Class name it ClassConnectionBuilder. Save the code you have above into that class.
'Creating connection string
Imports System.Data.SqlClient
Public Class ClassConnectionBuilder
Public Shared Function ConnectionStringBuilder(ByRef Server As String, ByRef database As String, _
ByRef userid As String, ByRef password As String) As String
Dim sqlConnString As New System.Data.SqlClient.SqlConnectionStringBuilder() With {
.DataSource = Server,
.InitialCatalog = database,
.UserID = userid,
.Password = password
}
Return sqlConnString.ConnectionString
End Function
End Class
Then you can use the build by either importing it then using it or providing a full "path".
IE
'Imported
'Importing would be: Imports yourprojectname.ClassConnectionBuilder
SqlConnectionStringBuilder(string,string,string,string)
'Not imported
ClassConnectionBuilder.SqlConnectionStringBuilder
Hope this helps
You could try something like this:
My.Settings.GCRConnectionString = "new string info here"
My.Settings.Save()
If you are wanting ID's to be unique, you might want to think about making it a primary key. Thus making it not possible to have multiples. Then you can wrap your insert in a try catch, the client will handle the "No duplicate keys" message.
What hericles is saying is true. I have found this out the hard way.
You could also write a tiny app with a text box. The user puts the sql command in the text box and presses a button. The button will fire off code that will bind the text string to a command and ExecuteNonQuery.
Can you post the code that is fired when the user changes the index?
Did you add the setting the My Project > Settings tab?
You can also do:
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Form2.Show()
Form2.TextBox1.Text = Me.TextBox1.Text 'Where Me references Form1 - the TextBox1 from Form1
End Sub
End Class
You could store all your data in an array in the text boxes "TextChanged" event procedure. Then use a statement like:
Dim tmp As String
If (arrayname[i].getLength() = 8) Then
tmp = arrayname[i]
arrayname{i] = "0" + tmp
End If
looping through the array checking each value.
You will need to the the reverse of what you did to get max.
ie. Look for lowest and compare for lowest value and store it in another temp.
Then compare the two after all calculations are completed.
Thank you stultuske, I feared I was getting to complex with it.
Will will loop through the array. Comparing the current index with the next index. Whichever index is higher, you will need compare to the value stored in the temporary variable. If the value in the temp variable is higher, keep it. If not, then write the higher value in the temp.
Example.
if (array[i] > array[i + 1] && array[i] > tempvar)
{
tempvar = array[i]
}
else if(array[i + 1] > array[i] && array[i + 1] > tempvar)
{
tempvar = array[i + 1]
}
After you have looped through the array and stored the highest value, you can then use
if (array[i] == tempvar)
{
numofinstances += 1
}
Where numofinstances is the number of the occurances of that number. Loop through a second time, checking all the values.
You will need to compare the values in the array, storing the higest in a temp value.
After that then you will need to search the array for that value and increment a counter every time you find that value.
What Jim is saying is correct. You will have to clear the list every time you change the combo box. That way you have a "fresh piece of paper" to load the new data back on.
If you wanted to limit the number of spaces, you can use Kothaisaravan's method, and incrememnt a counter every time they press the space bar. Then use an if statement with the counter = number and use the replace.
OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & spath & ";Persist Security Info=True")
Your connection string might be incorrect, it looks like it is missing some things.
Here is a good reference for connection strings:
That is fine.
If your deployment resolution is higher than the development resolution you will need to increase the size of form by:
Dragging the size increase handle of the form to the desired fit
or
Viewing the forms size properties and setting the size to the desired amount. This will require panning to the desired area using the scroll bars in form design.
An alternate way is to develop the application within the development resolution and dynamically scale up with the deployment's resolution. You can do this with margins and anchors.
You can do this on runtime by placing the code in the form's form_load event.
If that doesn't work. You can try by pulling from the current resolution by:
Me.Width = Screen.PrimaryScreen.Bounds.Width
Me.Height = Screen.PrimaryScreen.Bounds.Height
You can change the code to smaller by subtracted a value from the width/height code.