Quantcast
Channel: VBForums - Database Development
Viewing all 2918 articles
Browse latest View live

[RESOLVED] Options to accdb files

$
0
0
Hello Friends,

I develop in VB.NET and my Applications store data primarily in .accdb files, connected via Data.OleDb objects and using ACE provider.

I would like to know if there are best and free options that are also file-based, that is, don't require me to configure a network server, but just to place the file in any given network folder with read/write permissions.

Thank you very much!

add text to combobox from database and manually

$
0
0
I'm able to load and fill my combobox both manually and from the database. what i want to do is to be able to type in text in the combobox if the correct text is not found in the list of the combobox.

This however doesn't work and i receive an error message, telling me that i can't change text if i load it from the Database.

Is it possible to both fill a combobox from the database and add data manually to save it afterwards.

How to return a string value using ExecuteScalar

$
0
0
I created a simple conditional SQL command below and it works great doing ExecuteScalar but I was wondering what I could add to return a result. I see the RETURN TSQL command but I can't seem to get that to work. I can use ExecuteNonQuery and get the count of the number of rows affected but I'd rather learn how to return my own value from a TSQL command.
Code:

IF (EXISTS(SELECT * FROM TEST.dbo.People WHERE Name = 'Ted'))
BEGIN
-- Some text to indicate Ted already existed
END
ELSE
BEGIN
INSERT INTO TEST.dbo.People(Name) VALUES('Fred')
-- Some text to indicate that Fred was added
END

Thank you for taking the time to read my post.

really i need to use RS.Movenext

$
0
0
Code:


....
    Do While Not RS.EOF
        Print #1, RS.GetString(, 1000, ";");
        Y = Y + 1000
        DoEvents
'here i need Rs.Movenext?
    Loop
....

i store in txt file a recordset.
but really i need to use RS.Movenext?

[RESOLVED] Connect to MySQL on NAS

$
0
0
I've got a WD NAS drive that has MySQL Server running on it. (Many NAS drives nowadays have a Linux OS, Apache, MySQL and PHP pre-installed)

Anyway, Running phpMyAdmin on the device works fine. MySQL server is running.

I read somewhere that MySQL would have remote connections disabled by default but I install MySQL WorkBench on my desktop computer and give it the IP address of the NAS and the port (3306) and that connects no problem showing that MySQL Server is happy accepting connections from remote clients.

But I just can't connect from my own c# program.

MySqlConnection con = new MySqlConnection();
con.ConnectionString = "server=" + sServer + ";uid=admin;pwd=" + sPassword+ ";database=MY_TEST;";
con.Open();


If I include the port like "192.168.1.108,3306" or "192.168.1.108:3306" then it immediately throws an error
"Unable to connect to any of the specified MySQL hosts."

But it throws that same error even if I use invalid port numbers.

If I leave out the port number and just try connecting to the IP address then it sits spinning for a while and throws a timeout error.

My first thoughts would be that MySQL is simply ignoring remote connections - but - as a I said above - MySQL WorkBench, a program running on my desktop computer, has no problem connecting using the exact same credentials.

I've never had problems connecting to other databases such as MSSQL, Oracle, PostgreSQL but I'm probably just missing something simple with MySQL.

Anyone have any experience connecting to MySQL on a NAS drive?

System.Data.Common to MySql ?

$
0
0
I have a program that can connect to either JET or Microsoft SQL Server.

I Use System.Data.Common and have a function that gets me a connection to whatever database is in use.

Quote:

System.Data.Common.DbConnection getDbConnection()
{
System.Data.Common.DBConnection con;

If(UsingJET == true)
{
con = new System.Data.OleDb.Connection();
}
else
{
con = new System.Data.SqlClient.SqlConnection();
}

// Code for the connection string
// Code to Open the connection

return con;
}
I also have a similar thing for Command object.

The idea is that 99% of my code doesn't know or care what database it's connecting to. For example lines such as

System.Data.Common.DbDataReader rdr = cmd.ExecuteReader();

and then looping through the reader work just fine no matter what database we're using.

But now I'd like to include support for MySQL. But the MySql.Data.MySqlClient doesn't appear to be derived from System.Data.Common so I can't use the above method.

I suppose I could use object but then I'd be forever casting it to the relevant type. Maybe some way to use extension properties/methods on object?

Or is there a way to use System.Data.Common with MySQL Server?

I hope I'm making sense here. I'm not looking for anyone to write my code for me - just point me in the right direction - if there is one.

Thanks

MySql stored procedure : Premature termination after executing the DDL statement

$
0
0
Please have patience to go through my procedure
what it does is
[1] it changes the MySql user account login password
[2] then it do some editing of a field in the database

either the case the procedure should return the Success or failure messages , but whats happening is if the failure [ i,e if the DDL statement is not executed that is ALTER USER and EXECUTE PREPARED STATEMENT ] then the routine is returning the out put
other wise
the SELECT statement is not executed at all ,
i did a lot of googling but unable to understand the issue

here is my code
vb.net Code:
  1. DROP PROCEDURE IF EXISTS `testpfm`;
  2. CREATE DEFINER = `Proxyroot`@`localhost` PROCEDURE `testpfm`(UserToAlter VARCHAR(25) , LogHost VARCHAR(25) , NewPassWord VARCHAR(10))
  3. BEGIN    # ALTERS USERS PAssWorD
  4. # params dup 'Admin' , 'Admin' , 'localhost'
  5. DECLARE SucId SMALLINT DEFAULT 0 ;
  6. DECLARE BackEndMessage VARCHAR(250) DEFAULT "NO-ERROR" ;
  7. DECLARE UserExists SMALLINT DEFAULT 1 ; -- variable UserExists is from a function()
  8.  
  9. DECLARE EXIT HANDLER FOR SQLEXCEPTION SET SucId = 1 ;
  10. DECLARE EXIT HANDLER FOR SQLWARNING SET SucId = 1;
  11. START TRANSACTION ;
  12.  
  13. IF SucId = 1 THEN
  14. GET DIAGNOSTICS CONDITION 1 @p2 = MESSAGE_TEXT;
  15. SET BackEndMessage  = IFNULL(@P2,"ERROR LOG NOT RETURN BY PROC") ;
  16. ROLLBACK ;
  17. END IF;
  18.  
  19.  
  20. -- Change password of Current USER
  21. IF UserExists > 0 THEN  
  22. SET @SQLALTER = CONCAT("ALTER USER '",UserToAlter,"'@'",LogHost,"' IDENTIFIED BY '",NewPassWord,"';");
  23.  
  24. PREPARE AlterPassword FROM @SQLALTER ;EXECUTE AlterPassword ;
  25. DEALLOCATE PREPARE AlterPassword ;
  26. FLUSH PRIVILEGES ;
  27. -- It seems that the function Premature terminating here at FLUSH PRIVILEGES
  28.  
  29. UPDATE sec_accesscontrol SET sec_accesscontrol.LoginPwd = AES_ENCRYPT(NewPassWord ,101)WHEREsec_accesscontrol.LoginName = UserToAlter ; -- THIS IS IN
  30.  
  31. SET BackEndMessage  = "SUCCESS" ;
  32. COMMIT ;
  33. ELSE
  34. SET BackEndMessage  = "NO SUCH USER FOUND" ;
  35. SET SucId = 1 ;
  36. END IF;
  37.  
  38.  
  39.   SELECT SucId , BackEndMessage  ; -- WHY THE PROCEDURE NOT EXECUTING THIS LINE EVEN I TRIED TO SET THE OUT PARAMETER BUT NOT WORKS ???
  40. END;

Saving program constants in the Db?

$
0
0
I have a relatively simple program which has developed from a one-off sandbox to an application that now needs to be shared. A lot of what I hacked out contains 'magic numbers', hard coded values that should be a program setting, and I need to move them out. IE something that could be a constant in the program. And example might be a regular expression to extract some text. Normally I'd save these in the registry or in the My.Settings but this program will be run in distinct workstations or even networks. So imagine the kind of settings you might have in the registry. But that means distributing these changes when they happen. Which, of course, is still better than recompiling and redistributing the executable.

They all feed off of a common SQL Server and this seems like a good place to save these constants. But is that a good idea? I'm envisioning a table with a single row and tons of columns. It seems a little odd. Anyway I can think of several ways to do this but i was wondering how you guys like to do it.

Save New Record Problem

$
0
0
I'm working on an older database developed by someone else. Creating a new input form. The database is a split database
and the tables are in a saperate database and they are linked into the main database.
I place a "new Record button" and a "Save record" button. But when I go to save I'm getting an error message that want
allow me to save.

Msg: "The changes you requested to the table were not successful because they would create duplicate valvues in the index, primary key
or relationship. change the data in the field or fields that contain duplicate data, remove the index or redifine the index to permit duplicate
entries and try again".

So I remove the relationships and primary key in the source table and another table which had the same field (which had the key).
Saved and tried again. I got the same message.

So went to a support forum "https://support.microsoft.com/en-us/kb/884185"
None of the steps worked so I tried to add the module it showed and adding the table name and field.
---------------------------------
Sub ResetAuto()

Dim iMaxID As Long
Dim sqlFixID As String

iMaxID = DMax("<AutonumberFieldName>", "<TableName>") + 1

sqlFixID = "ALTER TABLE <TableName> ALTER COLUMN <AutonumberFieldName> COUNTER(" & <iMaxID> & ",1)"

DoCmd.RunSQL sqlFixID

End Sub
------------------------------------------
But it errored in the "sqlFixID =" line as a syntax error.

Does anyone have a answer on this one. I could check and see if I can use ADO and just add it to the table that way.
What is strange the original form that shows the data (a continuous form) has an add new button there but doesn't show the ID column and
has the same simple acAddnew code seems to work.

Thanks

How to expose MySql data on to WWW from a private network

$
0
0
I am using MySql database and it's hosted on a private LAN machine
But I need some views & procedures exposed to WWW web
So that it can be viewed by others too on the go
How can I do it please .

Looking for help installing SQL Server Express 2014.

$
0
0
Hi,

I am looking for some help installing SQL Server Express 2014 on a dedicated network server.

I tried installing once already and couldn't get a connection from my development box to the server. One article recommended restarting the service.

The service is now stopped and will not restart.
I rebooted the physical server and the SQL service will still not restart.

I am at the point I am thinking about doing a complete reinstall.

Can anyone lend a hand or recommend someone who would know how to do this?

Thanks,

table adapters empty at sql query

$
0
0
Hello dear friends,

i have a problem, which i can not solve alone, because i do not know wheter it is a bug or not. I would really appreciat it if you could help me with this.

Whenever i rightclick on my datatable (in the dataset designer window) and add a new sql query, just to get all coloumns of the table, all the content is empty. When i debug my programm i can see that all data has been wiped out.
I tried alot of things i tried in the databasedataset properties (copy only newer, dont copy and always copy) and same i tried on the database properties but no succes.
so why is the table content cleared whenever i add a new query on it? Thanks.

Access DB date issue?

$
0
0
Another database question.

I have an Access database I am trying to query.
The field is date/time

The following Query does not return what I expect.
Code:

    sSQL &= "SELECT * FROM tbl_Rework" & vbCrLf

    'Dim sDate1 As String = dtPicker1.Value.ToString("yyyy-MM-dd")
    'Dim sDate2 As String = dtPicker2.Value.ToString("yyyy-MM-dd")

    Dim sDate1 As String = dtPicker1.Value.ToString("MM/dd/yyyy")
    Dim sDate2 As String = dtPicker2.Value.ToString("MM/dd/yyyy")

    sDate1 = "#" & sDate1 & "#"
    sDate2 = "#" & sDate2 & "#"

    sSQL &= "WHERE RW_DueDate BETWEEN " & sDate1 & " AND " & sDate2 & vbCrLf

    sSQL &= "ORDER BY RW_DueDate" & vbCrLf

I'm getting records with duedate 8/21/212 through 2/2/2016
What gives?

[RESOLVED] Access DB date issue?

$
0
0
Another database question.

I have an Access database I am trying to query.
The field is date/time

The following Query does not return what I expect.
Code:

    sSQL &= "SELECT * FROM tbl_Rework" & vbCrLf

    'Dim sDate1 As String = dtPicker1.Value.ToString("yyyy-MM-dd")
    'Dim sDate2 As String = dtPicker2.Value.ToString("yyyy-MM-dd")

    Dim sDate1 As String = dtPicker1.Value.ToString("MM/dd/yyyy")
    Dim sDate2 As String = dtPicker2.Value.ToString("MM/dd/yyyy")

    sDate1 = "#" & sDate1 & "#"
    sDate2 = "#" & sDate2 & "#"

    sSQL &= "WHERE RW_DueDate BETWEEN " & sDate1 & " AND " & sDate2 & vbCrLf

    sSQL &= "ORDER BY RW_DueDate" & vbCrLf

I'm getting records with duedate 8/21/212 through 2/2/2016
What gives?

Retrieving a single row using MAX() function?

$
0
0
In the example attached screenshot, I have three rows of data. What I need to do is retrieve a single row that contains the most recent "dateCreated". I'm thinking that I would use the MAX() Function but I'm not sure how to construct the query. How would go about retrieving that single row?

Thanks,

A begineers question about binding of datagridview to database

$
0
0
I want to learn how to bind this control to a source of data. Is it possible to bind datagridview control and automatically save any changes made to datagridview? I want to write a small program (probably with use of SQLite). The best way would be to allow users to read and change data from database through this control.

I could not find any tutorial which explains this problem on a simple way. I know how to show data from database to gridview but I don't know how to write them back.

sorry on my English

Database Projects in VS

$
0
0
Hi all

Does anyone have an experience with Database Projects in VS? I have not used them before and am thinking of starting.

Need any insights or tips if anyone has any

Thanks
Gary

General Questions

$
0
0
I'm new to Access and VBA but Learning.
I have some general questions.

I'm more filmiliar with using "ADO" but I'm seeing where others use "DAO".
I can't do web apps here and we're on a secured large network. Which is preffered and easier to work with?

I want to use the most up to date version of access (2013 -365) but I need a good,
easy to understand book or resource that doesn't just cover web apps.
Can any suggest a good code book?

I'm working with a data base first developed in 2003 and its a spit database. the table
are in a folder with nine databases each one having tables.
Is this a good practice?

Also, last question:
I'm wanting create a search with multible user choices for criterias.
In a book I got there is so little on this. Mostly using quick query's.
The one I have has six combo boxes the user choices from and (toogle) search button.
Is this method one that y'all have seen in common use?

problem with updating datasource in vb.net

$
0
0
hi dears problem is same as written in topic title .the code below don't work

Code:

Private Sub ToolStripButtonSave_Click(sender As System.Object, e As System.EventArgs) Handles ToolStripButtonSave.Click
02
              Dim dt As New DataTable
03
              Dim strScl As String = "select * from scl"
04
              Dim adaptor As New OleDb.OleDbDataAdapter(strScl, My.Settings.Conn)
05
              adaptor.Fill(dt)
06
              sclBs.DataSource = dt
07
              'Dim nr As DataRow
08
              'nr = dt.NewRow()
09
              'nr("date") = TextBox1.Text
10
              'nr("totalfee") = TextBox2.Text
11
              'nr("comments") = TextBox3.Text
12
              'dt.Rows.Add(nr)
13
              sclBn.BindingSource = sclBs
14
              Dim nr = dt.NewRow()
15
              nr("comments") = TextBox3.Text
16
              nr("date") = TextBox1.Text
17
              nr("totalfee") = TextBox2.Text
18
              nr("computerid") = TextBox4.Text
19
              'Me.Validate()
20
              sclBs.EndEdit()
21
              adaptor.Update(dt)
22
              dt.Dispose()
23
              adaptor.Dispose()
24
          End Sub

thanks for ur reply

Need SELECT SQL advice

$
0
0
this is the schema of my table, i am having 3 tables one is Employee registry and another 2 is his activity logs.
what i need is the each employee last logged activity.

Quote:

CREATE TABLE `EmpRegistry` (`EmpName` varchar(25) NOT NULL ,
`AutoInc_EmpId_Pk` smallint NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`AutoInc_EmpId_Pk`)
)
;
Quote:

CREATE TABLE `EmpVisits` (`EmpId_Fk` smallint NOT NULL ,
`VisitedPlace` varchar(25) NOT NULL ,
`VisitedTime` datetime NOT NULL ,
`AutoInc_VisitId_Pk` smallint NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`AutoInc_VisitId_Pk`),
CONSTRAINT `EMPID_REFBIND` FOREIGN KEY (`EmpId_Fk`)
REFERENCES `EmpRegistry` (`AutoInc_EmpId_Pk`) ON DELETE RESTRICT ON UPDATE CASCADE
)
;
Quote:

CREATE TABLE `EmpCasualty` (`EmpId_Fk` smallint NOT NULL ,
`CasualtyReason` varchar(25) NOT NULL ,
`CasualtyDate` date NOT NULL ,
`AutoInc_CasId_Pk` smallint NOT NULL AUTO_INCREMENT ,
PRIMARY KEY (`AutoInc_CasId_Pk`),
CONSTRAINT `EMPID_CAS_BIND` FOREIGN KEY (`EmpId_Fk`)
REFERENCES `EmpRegistry` (`AutoInc_EmpId_Pk`) ON DELETE RESTRICT ON UPDATE CASCADE
)
;
Quote:

SELECTempregistry.EmpName ,
empvisits.VisitedPlace AS Last_VisitedPlace ,
empvisits.VisitedTime AS Last_VisitedReason ,
empcasualty.CasualtyDate AS Last_CasualtyDate ,
empcasualty.CasualtyReason AS Last_CasualtyReason
FROM
empregistry
LEFT JOIN
empvisits ON empregistry.AutoInc_EmpId_Pk = empvisits.EmpId_Fk
LEFT JOIN
empcasualty ON empregistry.AutoInc_EmpId_Pk = empcasualty.EmpId_Fk
how to write the SELECT statement which gets the last recorded log in each table
Viewing all 2918 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>