Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
REAL PROBLEM: I am making a admin control panel for my mysql database. I just learned the most of the stuff in vb.net i know everything now learning query language and i run into this question. I want that there would be a user validator(detector) what i mean is lets say someone is creating an account and the username exist it would show a messagebox that the username already exist and cancel creating the account.
Here is my code:
Imports MySql.Data.MySqlClient
Public Class Deathlairregnu
Dim MySqlConn As MySqlConnection
Dim MySqlCmd As MySqlCommand
Private Sub ButtonNUS_Click(sender As Object, e As EventArgs) Handles ButtonNUS.Click
MySqlConn = New MySqlConnection
MySqlConn.ConnectionString =
"server=localhost;userid=root;password=CONSORED;database=syscore"
Dim MySqlRea As MySqlDataReader
Try
MySqlConn.Open()
Dim Query As String
Query = "insert into syscore.normaluser (nusername,nemail,npass,nphone,ncity) values ('" & TextBoxNUsern.Text & "','" & TextBoxNEmail.Text & "','" & TextBoxNPass.Text & "','" & TextBoxNPhone.Text & "','" & TextBoxNCity.Text & "')"
MySqlCmd = New MySqlCommand(Query, MySqlConn)
MySqlRea = MySqlCmd.ExecuteReader
MessageBox.Show("Registration has been completed")
MySqlConn.Close()
Catch ex As MySqlException
MessageBox.Show(ex.Message)
Finally
MySqlConn.Dispose()
End Try
End Sub
End Class
OPTIONAL: Ok. I have another question maybe you can solve at the same time. How could i add guid generator when the register submit button is pressed if you know what i mean? i have it in my website asp.net that i made myself. Would be very nice and helpful.
Big thanks for those who will try to help me. I will check this topic every 5 minutes.
Adding a uniqueidentifier column and adding the default to generate new guid
Downvotes probably because you didn't paste your code here, plus the fact that the question has been asked and answered many times. Did you search before asking?
I did the important part. Optional is not needed for me but would've been good. Here: https://www.youtube.com/watch?v=ovoVfHW3Q8Y.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm doing a project and it's based on a previous Access project.
The DB I need to use is only accessed via the "Add-ins" tab, where I can find different buttons and tools to access the database.
For some reason I can't copy/paste or export the table to txt or excel spreadsheet, so I'm trying to find a way to manage the add-ins and access the table directly.
I can't find that table in the navigation bar (All Access Objects), so I guess this is the only way for me to find said table.
How do I reach the tables or queries defined in the add-ins tab?
Going to file->options->add-ins shows me that there are no add-ins installed
In the "Add-Ins" tab you see old custom menus, which are CommandBar objects.
There is no table for them, the following function lists all custom menus and should get you started.
Output is in the Immediate Window (Ctrl+G).
Public Function ListCustomCommandBars()
Dim cbarMenu As CommandBar
Dim Oberpunkt As CommandBarControl
Dim Unterpunkt As CommandBarControl
' ignore errors, e.g. menu items having no .OnAction property
On Error Resume Next
For Each cbarMenu In CommandBars
If Not cbarMenu.BuiltIn Then
Debug.Print vbCrLf & "=== " & cbarMenu.Name & " ===" & vbCrLf
For Each Oberpunkt In cbarMenu.Controls
Debug.Print Oberpunkt.Index & " " & IIf(Not Oberpunkt.Visible, "(--) ", "") & Oberpunkt.Caption
For Each Unterpunkt In Oberpunkt.Controls
Debug.Print , Unterpunkt.Index & " " & IIf(Not Unterpunkt.Visible, "(--) ", "") & Unterpunkt.OnAction, Unterpunkt.Caption
Next
Next
End If
Next
End Function
The most interesting part is .OnAction - it shows what a menu item does.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Dim cn As New MySql.Data.MySqlClient.MySqlConnection("server=...; User ID=...; password=...; database=...")
cn.Open()
Dim command As New MySqlCommand("select * from ...", cn)
Dim r As MySqlDataReader = command.ExecuteReader
While r.Read
Dim sb As StringBuilder = New StringBuilder()
While r.Read()
sb.AppendLine(r("messages"))
End While
TextBox2.Text = sb.ToString
End While
This code gets all messages from the MySQL table. How can i make it to only last(not read before) messages?
Supply to the code some kind of marker for where it left off. An incrementing identifier for the messages? A timestamp? It's your data, so it's your call. But basically, if you were to look at the data in the database manually, what value would you look for to determine "where you left off"? That's the value you want.
Then it's just a matter of putting that value into the WHERE clause. Something like this:
Dim command As New MySqlCommand("select * from SomeTable where MessageDate > #lastKnownDate", cn)
command.Parameters.Add(new MySqlParameter("#lastKnownDate", lastKnownDate))
// lastKnownDate would be the DateTime variable passed to this code.
// alternatively, use some other value as a "bookmark"
I have spent the last 2 years writing a bit of code which is working great at home but when I try and run it at work the network policies do not allow it.
It reads and writes to the following IP: "196.30.221.209"
http://196.30.221.209/phpmyadmin
My IT guys at work can’t get it to allow
Any suggestions. (port No. etc)
Im sure you had this question before
At home and other wifi areas its perfect.
With the following code:
Try
Dim PHPDB As String = "196.30.221.209"
Dim con As MySqlConnection = New MySqlConnection("Data Source=" + PHPDB + ";Database=####;User ID=####;Password=####;")
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM TEST_DB ", con)
con.Open()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, "TEST_DB")
DGV1.DataSource = ds.Tables(0)
con.Close()
Catch
End Try
Thanks a mill Guys
Well I can access it so you will need to talk to your IT guys. There isn't anything we can really tell you unless you be a lot more specific in what you've tried. I'm sure your work have port 80 unblocked...
What do you see when you try and access it at work? What other details do you have? Can you access another phpmyadmin server? Have you tried reinstalling phpmyadmin?
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to create and run a list of predefined queries on several similar databases.
The idea is open the database, run the queries, and then close.
Now I create each of them manually, run and then delete them from each database.
I don't know how to do it in VBA code.
Can anyone drop me a line on how to do it with a simple example?
You can use the Name property for each item in your database's QueryDefs collection to make a list of your saved queries. I think that addresses the title of your question. However the body of your question seems to ask for a lot more as far as I can tell.
You can load a string variable with the text from the SQL property of a QueryDef in your current database. Then use the OpenDatabase method to open another db file, and Execute that string there.
Public Sub RunQueryOnAnotherDb(ByVal pQuery As String, _
ByVal pRemoteDb As String)
Dim dbRemote As DAO.Database
Dim strSql As String
strSql = CurrentDb.QueryDefs(pQuery).SQL
'Debug.Print strSql
Set dbRemote = OpenDatabase(pRemoteDb)
dbRemote.Execute strSql, dbFailOnError
Debug.Print "RecordsAffected: " & dbRemote.RecordsAffected
dbRemote.Close
Set dbRemote = Nothing
End Sub
There's plenty of room to refine that one. You should add error handling for example. But, though quick & dirty, I hope it points you in a useful direction.
I tested it on my system like this, and it works with my db and query names.
Public Sub test_RunQueryOnAnotherDb()
Const cstrQuery As String = "qryTestDelete"
Const cstrRemoteDb As String = "C:\share\Access\0NewScratch.mdb"
RunQueryOnAnotherDb cstrQuery, cstrRemoteDb
End Sub
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am required to provide a way for users to choose which column they want to display from a table. The user has a combo box of column names in a form which they can select one of and then hit a button which opens a report. I wrote some code which creates an SQL query based on the user's input, but it's not being called. I've tried inserting MsgBox statements, asserts, etc., but it never gets called. If I use a macro instead, that will be run, but not this sub...
Private Sub Report_Open(Cancel As Integer)
Dim field As String
Dim sqlQuery As String
Dim ctl As Control
ctl = "Forms![RuleGroupForm]![selectRuleFieldCombo]"
field = "rules.[" & ctl & "]"
' E.g. if the field was "Source File", the final query should look like this:
'SELECT overview.ID, relationship.rulesID, rules.[Source File], overview.[Rule Group], rules.RulegroupID
'FROM (overview INNER JOIN relationship ON overview.id=relationship.id)
'INNER JOIN rules ON relationship.rulesID=rules.ID
'WHERE rules.[Source File] IS NOT NULL;
sqlQuery = "SELECT overview.ID, relationship.rulesID, " & field
sqlQuery = sqlQuery & ", overview.[Rule Group], rules.RulegroupID"
sqlQuery = sqlQuery & "FROM (overview INNER JOIN relationship ON overview.id=relationship.id) "
sqlQuery = sqlQuery & "INNER JOIN rules ON relationship.rulesID=rules.ID"
sqlQuery = sqlQuery & "WHERE " & field & " IS NOT NULL;"
Me.RecordSource = sqlQuery
Requery
debugText = "New SQL Query = " & sqlQuery
End Sub
Thanks.
Edit: Resolved, not sure how to respond to own question...
There are a few things to check, apart from close and open, when you get odd behaviour such as this in Access. One is to see if the event on the properties sheet for the form or report, Open in this case, still contains [Event Procedure] - occasionally a form or report can have the code, but the event is not marked. When developing, that is, adding forms, reports and code, it is a good idea to run Compact and Repair on a regular basis, this also means regular back-ups - a simple copy saves a lot of grief. Finally, when developing fairly regular Decompiles are a good idea. I keep a small script that I can drop the Access file on to run decompile.