|
You could redefine the columns to be automatically incrementing numbers. You use the "IDENTITY(x,y)" command when defining the table. (x = start, y = increment value).
e.g.
CREATE TABLE TableName
(UserId INT IDENTITY(1,1) NOT NULL,
UserName VARCHAR(50) NOT NULL,
Password VARCHAR(50) NOT NULL)
(Or using the GUI, you can set the Identity Specification property of the column to yes, and set the seed and increment there).
Personally though, using an autonumber as the primary key for a user isn't a very good design. Instead, I would define the primary key of a user as a "uniqueidenitifer" type (in SQL) and use guids in C#. Then, when you need to create a new user, you can call Guid.NewGuid() to create a new guid value that you use for that user.
Good luck.
Simon
|
|
|
|
|
Thanks Simon, what if i am not allowed to change the design , since the system is already in place. I have to make a new system from scratch which will use the existing user table to give the roles and access. Is there a way to append the new user id by 1 in both tables..
|
|
|
|
|
Complain to management that the DBA is not doing or capable of doing his job properly.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
Haha. Yeah, actually ignore my answer, just do this.
Simon
|
|
|
|
|
Ahh. Well in that case there is no easy way.
Are you sure you can't change the column properties. You should be able to modify it even if the database is already live.
If not, first you'll have to do a select statement to find out what the existing maximum value is (There is a command[^] specifically to do this)
Then you'll have to increment it, and include it when you insert the new user.
If multiple people/programs can be accessing your database at the same time, be careful to check you program correctly handles the situation where 2 people both try and insert a user at the same time. You'll get a duplicate insert exception on the second one, so you will need to handle that and try again. Or take a lock of some kind.
Simon
|
|
|
|
|
Having read the other posts and your replies, what you need to do is:
- open a transaction
- select the max u_id value plus one
- insert to both your tables
- commit the transaction.
This should ensure no duplication.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I'll admit I'm no SQL expert, but I don't think that opening a transaction will always ensure you don't get duplicate inserts in this case. All a transaction does is group the statements so you can ensure either all are executed (and a commit occurs) or none are executed (and a rollback occurs).
It is down to the isolation level settings[^] on the server to control what kind of locking takes place during a transaction.
The default (READ COMMITTED) allows other transactions to modify data in between statements in a transaction. Thus 2 transactions could both read the current max id (e.g. 5), both could then attempt an insert. The first would successful insert, the second would block. the first would then commit, which would allow the second to perform it's insert, which would cause a duplicate insert exception.
(I could be wrong about this, perhaps someone could explain if I have misunderstood the meaning of transaction isolation level)
Simon
|
|
|
|
|
Probably didn't explain it too well.
- begin tran
- update u_id table set u_id = u_id (does nothing except locks the table)
- select Max(u_id + 1)
- insert to both tables
- commit tran
While the u_id table is locked nobody else can update it.
So its not really the isolation level, it's my lack of explanation
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Ahh, yes, I see what your talking about now.
Simon
|
|
|
|
|
A better explanation always helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Some people have got you on the right lines. The standard way to do this horrible hack, is to have a separate table that contains a row for the table you want to update. This row normally consists of a table name, and a sequence number.
In your code, you start a transaction, then you update the row to be row + 1. Next, select the same row - as you've updated it, you have the lock on the row. If somebody else tries to perform this operation, you have the row locked. Commit the transaction, and you have a new unique sequence.
|
|
|
|
|
hi
im desperately looking for a third party control or software that can print a windows form,eg my windows form has a picturebox with some labels
thanks very much
regards paula
|
|
|
|
|
There are several article here on cp that do what you want. A simple search should find them all.
|
|
|
|
|
PaulaM wrote: Print Window
Did you Google for 'PrintWindow' ?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
yes i have they are all using Bitmap to capture the window and i would have liked a control that u can modify the font etc
regards paula
|
|
|
|
|
No can do.
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 alpha 4a out now (29 May 2008) ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
leppie wrote: Did you Google for 'PrintWindow' ?
I don't know about that but he has posted it on several forums.[^]
|
|
|
|
|
There are printers added on the remote machine.
I am using the following code to return the list of printers on this REMOTE machine.
Question:
Do you know why this code does NOT return the name of the printers?
Thanks
//list of remote printers...
string strWapiServer = "\\\\" + txtServerName.Text;
ConnectionOptions options = new ConnectionOptions();
options.Username = "username";
options.Password = "password";
options.Authority = "NTLMDOMAIN:omniad";
ManagementScope myScope = new ManagementScope(strWapiServer + "\\root\\cimv2", options);
SelectQuery oQuery = new SelectQuery("SELECT * FROM WIN32_Printer");
ManagementObjectSearcher oResults = new ManagementObjectSearcher(myScope, oQuery);
//Iterate through printers...
foreach (ManagementObject oItem in oResults.Get())
{
string strPrinterName = oItem.Properties["DeviceID"].Value.ToString();
}
|
|
|
|
|
Hi Friends
namespace Test
{
[STAThread]
public static void Main()
{
Application.Run(MainForm)
}
public class MainForm : Form
{
public int MaxValue;
public A a = new A();
public MainForm()
{
MainValue = 100;
}
}
public class A
{
public B b = new B();
public A()
{
}
}
public class B
{
public B()
{
}
}
}
How to access variable MaxValue from MainForm to class B
thanks in advance
-kk.tvm-
|
|
|
|
|
It's very simple. Did I understand you?
You should create an object from your MainForm class in B class and then you can reach the variable MaxValue.
While (true) { Human.isLearnable = true; }
|
|
|
|
|
I suppose that you mean to set the MaxValue variable in the MainForm constructor, not the MainValue variable.
You can not access the value of the MaxValue variable from the B constructor, as it hasn't been assigned when the instance of the B class is created.
Besides that you create the B instance before the MainForm constructor runs, you need a reference to the MainForm instance to access it's members. You can send the reference to the constructor of the A class, so that it can send the reference along to the constructor of the B class.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
you will have to use delegates!!! you´ll get used to it.
or download an articles about parent/child form method
if you are using more than 1 form, better forget it.
Use the above method or fill main_form with usercontrols to load pages(here you use delegate).It works fine for me.
see here an working exemple of delegates in action.
i trigger from usercontrol (with whatever event) a msg in form toolstrip_textbox
form
private void Form_Main_Load(object sender, EventArgs e)
{...
UserControl_RacePage_Child.Event_RacePageInfo += new UserControl_RacePage.Delegate_RacePageInfo(Page_Info);
...}
protected void Page_Info(string msg)
{ToolStripStatusLabel_MainInfo.Text = msg;}
usercontrol
public delegate void Delegate_RacePageInfo(string msg);
public event Delegate_RacePageInfo Event_RacePageInfo;
protected virtual void OnEvent_RacePageInfo(string msg)
{if (Event_RacePageInfo != null)
{ Event_RacePageInfo(msg); }}
protectec void button1_click(...)
{OnEvent_RacePageInfo("OK: Race added");}
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Here is my html file...
Problem..
i want to change $title$ while running a console application.
Can anyone help me?
Thnks in advance
Praji
|
|
|
|
|
Put your HTML-file into a string and change $TITLE$ with the help of the Replace()-method of the string-object.
Example:
<br />
string strHTML = "<html><head><title>$TITLE$</title></head><body></body></html>";<br />
strHTML = strHTML.Replace("$TITLE$", "www.codeproject.com");
|
|
|
|
|
Hi...
Plz... Help me...
I want some code for Converting a Number (money) to Words in Indian Format in C#.NET
eg.: if I enter 12345678 then it gives as ...
" ONE CRORE TWENTY THREE LAKHS FORTY FIVE THOUSAND SIX HUNDRED SEVENTY EIGHT "
if, anybody has this type of format Code .
regard&thanks
by
vidhya
|
|
|
|