Hi,
I have a question about SQL.
This question is a little to much on the IT side I suppose, but I will give it a try anyway as I do not have an IT forum account .
I'm writing a user management application with libnodave onboard and SQL. The customer wants an application that manages the user management. With an rfid reader, a UID will be red and forwarded from the HMI to the PLC and to the application on the server. I must use that UID to query in a SQL database and get the protection level.
The connection to the SQL database works. Using a SQLNonQuery for storing values works as well. But I've never queried data from a C# application, so I'm in a testing phase for this. I try with the ExecuteScalar command because I only need 1 value.
The folowing code does not work:
Are there SQL geeks out there to see where I go wrong ?
Thanks in advance,
Kind regards,
G
I have a question about SQL.
This question is a little to much on the IT side I suppose, but I will give it a try anyway as I do not have an IT forum account .
I'm writing a user management application with libnodave onboard and SQL. The customer wants an application that manages the user management. With an rfid reader, a UID will be red and forwarded from the HMI to the PLC and to the application on the server. I must use that UID to query in a SQL database and get the protection level.
The connection to the SQL database works. Using a SQLNonQuery for storing values works as well. But I've never queried data from a C# application, so I'm in a testing phase for this. I try with the ExecuteScalar command because I only need 1 value.
The folowing code does not work:
Code:
public static void SQLGetUser(String Server, String Database)
{
string connetionString = null;
SqlConnection cnn;
connetionString = "Server= " + Server + " ; Database=" + Database + ";Integrated Security = SSPI";
cnn = new SqlConnection(connetionString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
string cmdString = "Select * FROM Table_UsrMngt";
cmd.CommandText = cmdString;
cmd.Connection = cnn;
try
{
cnn.Open();
int Result = (int)cmd.ExecuteScalar();
MessageBox.Show(Convert.ToString(Result));
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! " + ex);
}
cnn.Close();
}
Are there SQL geeks out there to see where I go wrong ?
Thanks in advance,
Kind regards,
G
Last edited: