|
Thanks mr.
All my apologies I program under visual studio in csharp. And I installed sqlite server 3.9.1. I would like to know if I need to uninstall and use firefox ??
And how do I go about doing the exe and install it on another computer
|
|
|
|
|
Member 13322378 wrote: I program under visual studio in csharp. So why post in the Visual Basic forum? But, be that as it may, you can take a look at System.Data.SQLite[^]
|
|
|
|
|
Since the repost in the VS-category is newer than this thread, I'm assuming you're still struggeling with the concept. SQLite is not a server-database, it is meant as a lightweight database-solution for local usage of your application. That gives SQLite some advantages and some disadvantages over a server-product.
Richard linked you the System.Data.SQLite page; that wiki explains how to use and deploy SQLite. You'll probably end up xcopying two files along with your executable.
Some other points; if you have been "searching for five months" than you have wasted time that you could have used to read the documentation. Next, "help me" is not a decent subject-line. Everyone who posts here is looking for help - and your question is rather specific to SQLite and C#.
So, post your code, and let us see how you connect to your datafile. Once we have code, we can talk about possible locations where things can go wrong and what it is exactly that you need to verify.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
Sorry for the topic
"help me"
I used the dataset
Here is my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
namespace ACode
{
public partial class Form1 : Form
{
public static string randomstring(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWYZ0123456789";
Random random = new Random();
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
public Form1()
{
InitializeComponent();
}
private void infoCodeBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.infoCodeBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.dBCodeAleatoireDataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
this.infoCodeTableAdapter.Fill(this.dBCodeAleatoireDataSet.InfoCode);
}
private void btn100_Click(object sender, EventArgs e)
{
labelAffichage.Text = randomstring(4);
codeTextBox.Text = labelAffichage.Text;
prixCodeTextBox.Text = "100";
}
private void btn250_Click(object sender, EventArgs e)
{
labelAffichage.Text = randomstring(5);
codeTextBox.Text = labelAffichage.Text;
prixCodeTextBox.Text = "250";
}
private void btn500_Click(object sender, EventArgs e)
{
labelAffichage.Text = randomstring(6);
codeTextBox.Text = labelAffichage.Text;
prixCodeTextBox.Text = "500";
}
}
}
|
|
|
|
|
Where is the connectionstring? I do not see anything that references your database-file.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi
Please forgive me, this may be a simple answer for some. I have self taught myself VB.net and have developed some software for myself. I often get code samples for hardware that i use, but it is in C#. I have used code converters, but I still seem to get issues. The major issue I have is below. The C# code works perfectly, but the VB code gives me a "Object reference not set to an instance of an object.'" error when I call the connect sub. Please help.
C# Code
using SPORTident;
using System.Windows.Forms;
using SPORTident.Communication;
using System;
namespace SportidentMinimal
{
public partial class MainForm : Form
{
public Reader reader;
public MainForm()
{
InitializeComponent();
reader = new Reader
{
WriteBackupFile = true,
BackupFileName = System.IO.Path.Combine(Environment.CurrentDirectory, $@"backup\{DateTime.Now:yyyy-MM-dd}_stamps.bak")
};
reader.DeviceConfigurationRead += new DeviceConfigurationReadEventHandler(reader_DeviceConfigurationRead);
reader.InputDeviceChanged += new ReaderDeviceChangedEventHandler(reader_InputDeviceChanged);
reader.InputDeviceStateChanged += new ReaderDeviceStateChangedEventHandler(reader_InputDeviceStateChanged);
reader.CardRead += new SPORTident.DataReadCompletedEventHandler(reader_CardRead);
}
private void reader_DeviceConfigurationRead(object sender, StationConfigurationEventArgs e)
{
writeLog("StationConfigRead, OperatingMode: " + e.Device.OperatingMode);
writeLog("StationConfigRead, LegacyProtocolMode: " + e.Device.LegacyProtocolMode);
writeLog("StationConfigRead, AutoSend: " + e.Device.AutoSendMode);
writeLog("StationConfigRead, FirmwareVersion: " + e.Device.FirmwareVersion);
writeLog("StationConfigRead, CodeNumber: " + e.Device.CodeNumber);
writeLog("StationConfigRead, SerialNumber: " + e.Device.SerialNumber);
}
private void reader_InputDeviceStateChanged(object sender, ReaderDeviceStateChangedEventArgs e)
{
writeLog("InputDeviceStateChanged: " + e.PreviousState + " => " + e.CurrentState);
}
private void reader_InputDeviceChanged(object sender, ReaderDeviceChangedEventArgs e)
{
writeLog("InputDeviceChanged: " + e.PreviousDevice + " => " + e.CurrentDevice);
}
private void reader_CardRead(object sender, SportidentDataEventArgs e)
{
SportidentCard card = e.Cards[0];
writeLog("Card read: " + card.Siid);
}
private void button_refresh_Click(object sender, EventArgs e)
{
writeLog("Refresh pressed");
clearSIDevices();
getSIDevices();
}
private void button_sportidentConnect_Click(object sender, EventArgs e)
{
writeLog("Connect pressed");
try
{
connect();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void button_sportidentDisconnect_Click(object sender, EventArgs e)
{
writeLog("Disconnect pressed");
disconnect();
}
private void writeLog(string text)
{
if (listBox_log.InvokeRequired)
{
listBox_log.Invoke(new Action(() => writeLog(text)));
}
else
{
listBox_log.Items.Add(text);
listBox_log.SelectedIndex = listBox_log.Items.Count - 1;
listBox_log.SelectedIndex = -1;
}
}
private void clearSIDevices()
{
writeLog("Clearing list of devices");
comboBox_sportidentDevices.Items.Clear();
}
private void getSIDevices()
{
writeLog("Scanning for available devices");
ReaderDeviceInfo.GetAvailableDeviceList();
foreach (ReaderDeviceInfo device in ReaderDeviceInfo.AvailableDevices)
{
comboBox_sportidentDevices.Items.Add(device);
writeLog("Adding device: " + device.DeviceName);
}
if (comboBox_sportidentDevices.Items.Count > 0)
{
writeLog("Found " + comboBox_sportidentDevices.Items.Count + " devices");
comboBox_sportidentDevices.SelectedIndex = 0;
}
else
{
writeLog("No devices found");
}
}
private void connect()
{
ReaderDeviceInfo readerDeviceInfo = (ReaderDeviceInfo)(comboBox_sportidentDevices.SelectedItem);
reader.InputDevice = readerDeviceInfo;
reader.OutputDevice = new ReaderDeviceInfo(ReaderDeviceType.None);
reader.OpenInputDevice();
reader.OpenOutputDevice();
comboBox_sportidentDevices.Enabled = false;
button_refresh.Enabled = false;
button_sportidentConnect.Enabled = false;
button_sportidentDisconnect.Enabled = true;
}
private void disconnect()
{
comboBox_sportidentDevices.Enabled = true;
button_refresh.Enabled = true;
button_sportidentConnect.Enabled = true;
button_sportidentDisconnect.Enabled = false;
reader.CloseInputDevice();
}
}
}
VB.NET Code
Imports SPORTident
Imports SPORTident.Communication
Public Class Results_Capture_Enduro
Public reader As Reader
Public Sub New()
InitializeComponent()
reader = New Reader() With {
.WriteBackupFile = True,
.BackupFileName = System.IO.Path.Combine(Environment.CurrentDirectory, "backup\{DateTime.Now:yyyy-MM-dd}_stamps.bak")
}
AddHandler reader.DeviceConfigurationRead, New DeviceConfigurationReadEventHandler(AddressOf reader_DeviceConfigurationRead)
AddHandler reader.InputDeviceChanged, New ReaderDeviceChangedEventHandler(AddressOf reader_InputDeviceChanged)
AddHandler reader.InputDeviceStateChanged, New ReaderDeviceStateChangedEventHandler(AddressOf reader_InputDeviceStateChanged)
AddHandler reader.CardRead, New SPORTident.DataReadCompletedEventHandler(AddressOf reader_CardRead)
End Sub
Private Sub reader_DeviceConfigurationRead(sender As Object, e As StationConfigurationEventArgs)
writeLog("StationConfigRead, OperatingMode: " & e.Device.OperatingMode.ToString)
writeLog("StationConfigRead, LegacyProtocolMode: " & e.Device.LegacyProtocolMode.ToString)
writeLog("StationConfigRead, AutoSend: " & e.Device.AutoSendMode.ToString)
writeLog("StationConfigRead, FirmwareVersion: " & e.Device.FirmwareVersion.ToString)
writeLog("StationConfigRead, CodeNumber: " & e.Device.CodeNumber.ToString)
writeLog("StationConfigRead, SerialNumber: " & e.Device.SerialNumber.ToString)
End Sub
Private Sub reader_InputDeviceStateChanged(sender As Object, e As ReaderDeviceStateChangedEventArgs)
writeLog("InputDeviceStateChanged: " & e.PreviousState.ToString & " => " & e.CurrentState.ToString)
End Sub
Private Sub reader_InputDeviceChanged(sender As Object, e As ReaderDeviceChangedEventArgs)
writeLog("InputDeviceChanged: " & e.PreviousDevice.ToString & " => " & e.CurrentDevice.ToString)
End Sub
Private Sub reader_CardRead(sender As Object, e As SportidentDataEventArgs)
MessageBox.Show("got here")
Dim card As SportidentCard = e.Cards(0)
writeLog("Card read: " & card.Siid.ToString)
End Sub
Private Sub btnRefresh_Click(sender As Object, e As EventArgs) Handles btnRefresh.Click
writeLog("Refresh pressed")
clearSIDevices()
getSIDevices()
End Sub
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
writeLog("Connect pressed")
connect()
End Sub
Private Sub btnDisconnect_Click(sender As Object, e As EventArgs) Handles btnDisconnect.Click
writeLog("Disconnect pressed")
disconnect()
End Sub
Private Sub writeLog(Text As String)
If listBox_log.InvokeRequired Then
listBox_log.Invoke(New Action(Sub() writeLog(Text)))
Else
listBox_log.Items.Add(Text)
listBox_log.SelectedIndex = listBox_log.Items.Count - 1
listBox_log.SelectedIndex = -1
End If
End Sub
Private Sub clearSIDevices()
writeLog("Clearing list of devices")
cbbSportIdentDevices.Items.Clear()
End Sub
Private Sub getSIDevices()
writeLog("Scanning for available devices")
ReaderDeviceInfo.GetAvailableDeviceList()
For Each device As ReaderDeviceInfo In ReaderDeviceInfo.AvailableDevices
cbbSportIdentDevices.Items.Add(device)
writeLog("Adding device: " & device.DeviceName.ToString)
Next
If cbbSportIdentDevices.Items.Count > 0 Then
writeLog("Found " & cbbSportIdentDevices.Items.Count.ToString & " devices")
cbbSportIdentDevices.SelectedIndex = 0
Else
writeLog("No devices found")
End If
End Sub
Private Sub connect()
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
reader.InputDevice = readerDeviceInfo
reader.OutputDevice = New ReaderDeviceInfo(ReaderDeviceType.None)
reader.OpenInputDevice()
reader.OpenOutputDevice()
End Sub
Private Sub disconnect()
'reader = New Reader()
cbbSportIdentDevices.Enabled = True
reader.CloseInputDevice()
End Sub
End Class
The exception seems to come when I have called the connect sub. I am assuming it doesn't like the 4 lines where I reference "reader".
Private Sub connect()
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
reader.InputDevice = readerDeviceInfo
reader.OutputDevice = New ReaderDeviceInfo(ReaderDeviceType.None)
reader.OpenInputDevice()
reader.OpenOutputDevice()
End Sub
Shane
modified 21-Jul-17 7:43am.
|
|
|
|
|
Please edit your question and show us where the exception occurs.
|
|
|
|
|
Do you have an Item selected inside the Combobox (cbbSportIdentDevices.SelectedItem) ?
What do you see by using the Debugger (in case of exeption) ?
|
|
|
|
|
Hi Ralf
Yes I select a Com port. For my current scenario it happens to be COM5. Its weird that it all works perfectly in C#, but in my project, when I have converted to VB, it gives this exception.
|
|
|
|
|
Hi Shane,
I never thought that you assign a Com-Port at this place.
So ... there are some Information missing to go further.
How is ReaderDeviceInfo declared ?
How and where do you have the COM-Port in your code ? Where do you assign an initialize it ?
I think that are parts which belong to the Designer-Scripts from the C#-Project - you should look also there and perhaps complete your code.
If not try to answer my questions ...
|
|
|
|
|
Perhaps little background will help as I can't post an image of the form. I have an RFID reader which connects to the computer via a usb. The sample app from the supplier (the c# Code). Just provides a list of available devices in a combobox after clicking the refresh button. This all works in my VB code as well and after clicking the button it shows a list of (COM1 and COM5 on my laptop) in the combobox. After selecting the correct COM from the dropdown (COM5 in my case). You then click the connect button and it is at this point that my VB code falls over, but the C# code works fine. The form is very simple, I have compared the designer code and nothing different there either. I'm just very confused as to why the VB code gives the null exception but the C# code doesn't. Yet the code is almost identical.
The writelog is just a list box which provides a log of all the steps taken and events which are initiated by the reader.
Hope this helps
Regards
Shane
|
|
|
|
|
Hi Shane,
when I compare both codes (C# vs. VB) I can't see any relevant difference. For me both codes should do the same.
But any difference must be there ...
So : what about the Visual Studio Settings ? Have you added the required DDL's to the references (I hope the name is right - In German it's called 'Verweis') of your Project ?
Greetings
Ralf
|
|
|
|
|
Yes, all dll's have been added. Very confusing to me, why it doesnt work
|
|
|
|
|
If I put the reader = New Reader() in the connect sub, the error goes away, but nothing works like it should. it doesnt pick up the events or anything
Private Sub connect()
reader = New Reader()
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
reader.InputDevice = readerDeviceInfo
reader.OutputDevice = New ReaderDeviceInfo(ReaderDeviceType.None)
reader.OpenInputDevice()
reader.OpenOutputDevice()
End Sub
|
|
|
|
|
Let's get back to the ComboBox and it's ReaderDeviceInfo ...
I can't see a code-line where the ComboBox is assigned/filled AND with what it is filled.
I suggest that you should look there ...
|
|
|
|
|
Shane James wrote: If I put the reader = New Reader() in the connect sub, the error goes away, but nothing works like it should. it doesnt pick up the events or anything
This is normal: you create a new instance of the Reader class but this one is not configured like the first one was in the constructor of Results_Capture_Enduro . But I don't think the problem is here, you should remove this line.
You did not tell us which variable triggers the exception. To find it you can remove the try...catch block around the call to connect() to let the debugger stop at the line the exception occurs.
There is one line where the VB code is not equivalent to its C# counterpart:
Dim readerDeviceInfo As ReaderDeviceInfo = CType((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
The strictly equivalent version would be:
Dim readerDeviceInfo As ReaderDeviceInfo = DirectCast((cbbSportIdentDevices.SelectedItem), ReaderDeviceInfo)
See this article:
DirectCast vs. CType[^]
for explanations. In general using CType for a simple type cast is dangerous because it will try to do something even if the cast is not possible, so that the error may propagate to other parts of the code where it is difficult to understand.
NB. Also be careful when translating from C# to VB.NET as the latter is not really case sensitive which may cause compilation errors:
vb.net - Is VB really case insensitive? - Stack Overflow[^]
|
|
|
|
|
Shane James wrote: it shows a list of (COM1 and COM5 on my laptop) in the combobox. I am going to guess that it does not contain a list of strings that represent comports, but objects.
Show us how the VB version that initializes the combobox looks like.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I've got this code that queries a table and returns a model:
Public Function GetRightCategory(Id As Integer) As RightCategoryModel
Dim result As New RightCategoryModel
Dim queryCmd As String
queryCmd = "SELECT RightCategoryId, Category, Description, IsDeleted FROM tblRightCategories WHERE RightCategoryId = " + CStr(Id)
Dim Db As Database
Dim rs As Recordset
Set Db = DBEngine(0)(0)
Set rs = Db.OpenRecordset(queryCmd)
If rs.RecordCount > 0 Then
With result
.Id = rs.Fields("RightCategoryId")
.Category = rs.Fields("Category")
.Description = rs.Fields("Description")
.IsDeleted = rs.Fields("IsDeleted")
End With
End If
set GetRightCategory = result
Everything works great until I get past the last line. Then I get "Object doesn't supprot this property or method"
What's wrong here?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
You have result defined as a RightCategoryModel type. How is GetRightCategory defined?
|
|
|
|
|
It's at the top. The formatter didn't format it
"Public Function GetRightCategory(Id As Integer) As RightCategoryModel"
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Sorry, I can't see anything untoward in that. I use functions in both Excel and Word and have never had a problem with return values.
|
|
|
|
|
I saw something while Googling that suggested that this record set syntax is what it doesn't like:
I have this:
.Id = rs.Fields("RightCategoryId")
The Google result had this:
.Id = rs!RightCategoryId
Is there any difference in these two syntaxes?
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
|
How is this method being called? The "Set ..." has to be there on the line of code calling this method.
In VBA/6, you had to specify "Set something = MyMethodCallReturningAnObject()". Any method returning an intrinsic type doesn't need the Set before the assignment, but methods that return objects do.
|
|
|
|
|
That did it. I didn't have the 'set' in the call to the method.
Thank you!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|