I have a login form in c# connected to sql server table CustomerTbl I want a query to be…
Jump to turn (13)
- 1I have a login form in c# connected to sql server table CustomerTbl I want a que
- 2How would it know to select CustomerID column?
- 3How do I make a variable available in one form to all forms
- 4is this good? Con.Open(); SqlCommand cmd = new SqlCommand("Select IDENTCURRENT('
- 5its giving me this error System.InvalidCastException: 'Object cannot be cast fro
- 6but there are entires in the table
- 7what query can I use in sql to give me last entry
- 8SELECT TOP 1 FROM CustomerTbl ORDER BY CustomerID DESC , how do I select the ID
- 9Con.Open(); SqlCommand cmd = new SqlCommand("SELECT TOP 1 CustomerID FROM Custom
- 10instead of rdr.Getint32 what do I use to get a string?
- 11public static class globalvariable { public static string CustomerName=Login.Nam
- 12How to I give public static string CustomerName a value that is available in a v
- 13when I do for example String CName=GlobalVariables.CustomerName in another form
- User
I have a login form in c# connected to sql server table CustomerTbl I want a query to be able to set int i= (last CustomerID) +1
- Assistant
Assuming CustomerID is an identity column in the CustomerTbl table, you can retrieve the last inserted CustomerID using the following SQL query:
SELECT IDENT_CURRENT('CustomerTbl')
This query will return the last identity value generated for the specified table, in this case 'CustomerTbl'. You can then use this value to set the value of i to the last CustomerID plus one.
Here's an example of how you can use this query in your C# code:
// Create a SQL connection SqlConnection connection = new SqlConnection(connectionString);