|
There are several problems with an auto increment column , mostly involves using foreign keys and moving the data around the databse if you ever had to..its always a good idea to control what your keys are and not let something decide for you, then you have to get the new key before you insert so you dont have this problem.. I dont know your data so i cant suggest a good key, but if you're happy with a simple incrementing integer, why not just do table that contains several rows with the id name, its current value, and what to increment it by and use a stored procedure to return the current value then increment it, that way 2 synchrous requests cant duplicat the value...its a little more work but solves a lot of problems now and in the future. onces its set up you can use it all over the place when the data you're trying to store doesnt give you a decent primary or composite key.
|
|
|
|
|
I understood you, but database is already working (in production), so I can't modify it.
Thank you very much.
--
[Adrián Córdoba]
|
|
|
|
|
then the only way i know if is to insert your row then go looking for it in the dataset, if you are using a data adapter. If you are using a stored procedure you could have the SP return the new identity. sorry auto increments make things harder than they should be sometimes.
|
|
|
|
|
Hi every one. I don't know if this is the right section to make this question. So if it isn't sorry
How can I use the click event of the print button on the toolbox of an crystalreportviewer? The problem is that a need to update a field in my database when the report is for the fist time printed.
Thank you all.
|
|
|
|
|
Hi all,
i used this code,but it has this error:{ expected OR } expected in,i bold place of this error occured ,i tried resolve this errors but i couldn't.
public bool ValidateNewUser(string strAlias, string strFirst, string strLast)
{
SqlConnection MyConn = new SqlConnection(ConfigurationSettings.AppSettings["MyOnlineShoppingConnectionString2"]);
SqlCommand MyCmd = new SqlCommand("sp_CheckForDuplicates", MyConn);
MyCmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter objParam3;
SqlParameter objReturnParam;
objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar);
objParam2 = MyCmd.Parameters.Add("@FirstName", SqlDbType.VarChar);
objParam3 = MyCmd.Parameters.Add("@LastName", SqlDbType.VarChar);
objReturnParam = MyCmd.Parameters.Add("@Duplicates", SqlDbType.Int);
objReturnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = strAlias;
objParam2.Value = strFirst;
objParam3.Value = strLast;
try
{
if (MyConn.State == ConnectionState.Closed)
{
MyConn.Open();
MyCmd.ExecuteNonQuery();
if (Convert.ToInt32(objReturnParam.Value )> 0)
{
lblResult.Text = "UserName already exists or you are already a registered user!";
return false;
}
else
{
return true;
}
MyConn.Close();
}
catch (Exception ex)
{
lblError.Text = "Error Connecting to Database!";
}
}
}
Please Help Me,
Thank You,
<div class="ForumSig">Hoda </div>
<div class="ForumMod">modified on Monday, May 19, 2008 12:00 PM</div>
|
|
|
|
|
Saba02,
I think you could of solved this your self if you took 2mins to think about it...
public bool ValidateNewUser(string strAlias, string strFirst, string strLast)
{
SqlConnection MyConn = new SqlConnection(ConfigurationSettings.AppSettings["MyOnlineShoppingConnectionString2"]);
SqlCommand MyCmd = new SqlCommand("sp_CheckForDuplicates", MyConn);
MyCmd.CommandType = CommandType.StoredProcedure;
SqlParameter objParam1;
SqlParameter objParam2;
SqlParameter objParam3;
SqlParameter objReturnParam;
objParam1 = MyCmd.Parameters.Add("@UserName", SqlDbType.VarChar);
objParam2 = MyCmd.Parameters.Add("@FirstName", SqlDbType.VarChar);
objParam3 = MyCmd.Parameters.Add("@LastName", SqlDbType.VarChar);
objReturnParam = MyCmd.Parameters.Add("@Duplicates", SqlDbType.Int);
objReturnParam.Direction = ParameterDirection.ReturnValue;
objParam1.Value = strAlias;
objParam2.Value = strFirst;
objParam3.Value = strLast;
try
{
if (MyConn.State == ConnectionState.Closed)
{
MyConn.Open();
MyCmd.ExecuteNonQuery();
if (Convert.ToInt32(objReturnParam.Value) > 0)
{
lblResult.Text = "UserName already exists or you are already a registered user!";
return false;
}
}
else
{
return true;
}
MyConn.Close();
}
catch (Exception ex)
{
lblError.Text = "Error Connecting to Database!";
}
}
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
Well for starters you have an extra '}' at the end. In Visial Studio (or almost every good text editor) there is a way to match braces, brackets and parenthesis. Give it a shot; you'll find the culprit in no time.
|
|
|
|
|
You should do what I do. If I have a real stumper on my hands, I start writing a message here, but I ALWAYS go back and look a little harder at my code before posting the message. It doesn't always work out, but I have discovered quite a few "stupid programmer tricks" that saved me from having to ask a question.
BTW, your try block starts too late - it really should be around ANY code that can throw an exception.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Good Day,
IF File.WriteAllBytes and File.ReadAllBytes does not have the ability to "return" the progress of the operation, say writing a 1GB file, then what are my other options?
My major concern is to be able to extract the progress of the byte writing/reading since I am working with really large files.
Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Can't you read/write them in chunks of arbitrary size, for example 1mb per chunk?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Yes, that is what I'm hoping to achieve. The "older" way to write files.
But I need some example codes or a link perhaps.
Thank you.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
You can use BinaryReader.Read[^] in a loop, starting with offset 0 until the end of the file is reached, increasing the offset with the chunk size in every loop step.
If you wish I can post an example later (unless you won't find one on google or someone else answers in the meantime), I have to leave right now.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Please do so if you have time. Thanks!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Hello,
Perhaps you can use timer and keep an eye on disk space being consumed...
Like:
1. Have a timer
//do what you want..
2. Get free space in hard-disk you are playing with big files
3. Play with files
in timer tick check free space again, you do know the size of the file right? use these two and check approximately how much work has been done.
HTH!
Regards,
Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
Hi,
That approach won't work, unfortunately. I already tried a similar approach using FileSystemWatcher. The problem is that File.WriteAllBytes() will initially write the full file size. I do not know why.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Why not try out with System.IO.DriveInfo?
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
|
|
|
|
|
Alright, I'll try it and report back.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Adeel Chaudhry wrote: Why not try out with System.IO.DriveInfo?
Hi, I've tried it and the outcome is also the same as using the FileSystemWatcher.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Take a look at the FileStream class. That's the basis of reading and writing files, that's what WriteAllBytes, ReadAllBytes and all the different reader and writer classes use to access files.
MSDN Library: FileStream class[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Hi Guffa,
My problem is that I don't know how to write a bytearray chunk by chunks.
Say I already have byte[] Data, and I want to write it 1024 bytes at a time.
Regards
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Use a loop.
Example:
int pos = 0;
int left = data.Length;
while (left > 0) {
int len = Math.Min(left, 1024);
stream.Write(data, pos, len);
pos += len;
left -= len;
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Exactly what I needed! Thank you!
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
|
|
|
|
|
Hi Guys
I am trying to write GoalSeek method of excel in c#, can anyone help me to get the algorithm behind Goal Seek, do not give me the VB examples, need something more generic.
Thanks in advance.
happy coding!
|
|
|
|
|
Have you Googled for [^]?
(At first sight, your task appears a bit complex )
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Hi,
Hope this is the right place to ask, I have the following problem:
I have a .Net 2.0 Forms/C# solution in visual studio 2005, running on windows Vista Ultimate (both fully up to date with patches).
When I open up VS2005 and select the project from the VS Start page, weird stuff starts to happen: While loading the project, VS decides to spontaneously start up the application (without me having touched any buttons).
I can't stop the program once it's running from the IDE: shift-F5 and the debug menu don't work. But as soon as I close my app manually, Visual Studio sometimes crashes immediately.
This happens about a third of the times I open my Visual Studio project. But if it doesn't, there's always a chance of it happening at some random time while I'm happily coding about: My project will just start to run spontaneously: No compiling or anything, just running the version I last compiled.
I've had this VS installation for over a year now, never had any problems with it. The problem only seems to occur with one specific solution: I don't have it with any other solutions I made.
Any advice?
Standards are great! Everybody should have one!
|
|
|
|