|
EDden2Fly wrote:
I wana know what happens when this number reachs its maximum value, and whats the approach in this case?
Erm...this number is so big that you'd run out of disk space just to hold all the records way before you'd reach the max value, I would imagine.
If you use the decimal type with maximum precision, that's 10^38 unique identities! "bigint" is 9,223,372,036,854,775,807.
OK, if you use int (2Gb), smallint (32K), or tinyint (255), then yes, you'd have a problem.
So, what happens when you set an identity to a tinyint type and add the 256'th record?
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
Hunt The Wumpus
RealDevs.Net
|
|
|
|
|
An Exception of type SqlException is thrown with a message indicating an arithmetic overflow
Thank you so much Marc
- Den2Fly
---
"Art happens when you least expect it."
|
|
|
|
|
I use ado.net do something to mdb database. I found out the mdb database's size was been increased when it run some time.I can't confirm what it is cause.
It is my class,
using System;
using System.Data;
using System.Data.OleDb;
using System.Collections;
namespace RoadLib
{
///
/// NdnDataBase の概要の説明です。
///
public class NdnDataBase
{
protected string m_strConnectionString;
private OleDbConnection m_connection = null;
private OleDbTransaction m_transaction = null;
///
/// NdnDataBase の概要説明です
///
public NdnDataBase()
{
//
// TODO: コンストラクタ ロジックをここに追加してください。
//
m_connection = null;
}
///
/// NdnDataBase の概要説明です
///
/// <param name="strConnectionString" />
public NdnDataBase(string strConnectionString)
{
m_strConnectionString = strConnectionString;
m_connection = null;
}
///
/// DBコネクションを取得します
///
public OleDbConnection connection
{
get { return m_connection; }
}
///
/// DBトランザクションを取得します
///
public OleDbTransaction transaction
{
get { return m_transaction; }
}
///
/// データベースを開くために使用接続する
///
public string connectionString
{
get { return m_strConnectionString; }
set { m_strConnectionString = value;}
}
///
/// 指定のデータベースでセッションを開く
///
/// <returns>
public OleDbConnection DBOpen()
{
if(m_connection == null)
{
try
{
//データベース接続パラメータを取得
if (m_strConnectionString == "")
{
return null;
}
m_connection = new OleDbConnection(m_strConnectionString);
//DBオープン
m_connection.Open();
}
catch(Exception err)
{
//NdnPublicFunction.WriteLog(m_strLogFileName, err.Message);
m_connection = null;
throw (err);
}
}
return m_connection;
}
///
/// データベースでセッションを閉じる
///
/// <param name="connection" />
public void DBClose()
{
try
{
//DBクローズ
if (m_connection != null)
{
m_connection.Close();
}
}
catch
{
}
finally
{
//初期値を設定
m_transaction = null;
m_connection = null;
}
}
///
/// SQLステートメントを実行
///
/// <param name="strCommandText" />
/// <param name="connection" />
/// <param name="transaction" />
/// <returns>
public bool ExecSql(string strCommandText, OleDbConnection connection, OleDbTransaction transaction)
{
bool bReturn = false;
OleDbCommand dbCommand = new OleDbCommand(strCommandText, connection, transaction);
try
{
dbCommand.ExecuteNonQuery();
bReturn = true;
}
catch( Exception err)
{
throw (err);
}
return bReturn;
}
///
/// データベースでトランザクションを開始します
///
/// <returns>
public bool BeginTrans()
{
bool bReturn = false;
try
{
if (m_connection != null)
{
m_transaction = m_connection.BeginTransaction();
bReturn = true;
}
}
catch (Exception err)
{
throw err;
}
return bReturn;
}
///
/// データベースでトランザクションをコミットします
///
/// <returns>
public bool CommitTrans()
{
bool bReturn = false;
try
{
if (m_transaction != null)
{
m_transaction.Commit();
bReturn = true;
}
}
catch (Exception err)
{
throw err;
}
finally
{
m_transaction = null;
}
return bReturn;
}
///
/// データベースでトランザクションをロールバックします
///
/// <returns>
public bool RollbackTrans()
{
bool bReturn = false;
try
{
if (m_transaction != null)
{
m_transaction.Rollback();
bReturn = true;
}
}
catch (Exception err)
{
throw err;
}
finally
{
m_transaction = null;
}
return bReturn;
}
}
}
I use it to operate mdb database.
for example:
NdnDataBase database = new NdnDataBase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nara.mdb;User Id=admin;Password=;");
try
{
database.DBOpen();
database.BeginTrans();
database.ExecSql("Delete from ttt");
...
database.ExecSql("Insert into ttt values(1, 2)", database.connection, database.transaction);
database.CommitTrans();
...
}
catch
{
database.RollbackTrans();
}
finally
{
database.DBClose();
}
it operation is in a timer event.
At last, the database is bad.
|
|
|
|
|
What do you mean by "the database is bad"?
Without providing a more detailed error description it's very hard to help you!
Just one thing that comes to mind: Do you disable your timer while your function is executing? If not, the cause for your problems could be the timer re-entering the function while the previous timer event is still executing...
Regards,
mav
|
|
|
|
|
You may want to try Compact and Repair Database. We have a system that has the UI and Database separated. The front end never changes but it continues to grow just from using it! Since there is no data changes being made, I know that there are "features" in .mdb files that just need routine maintenance.
|
|
|
|
|
Access doesn't reclaim disk space when deleting or altering recrods until you tell it to do a compact and repair. Also, indexing sometimes places pads so that it can be better optimized. Really, it isn't a problem if you do regular housecleaning.
Marc
Microsoft MVP, Visual C#
MyXaml
MyXaml Blog
Hunt The Wumpus
RealDevs.Net
|
|
|
|
|
Dear friends!
I have a strange problem with C# and the Graphics-class.
My Form contains a pictureBox, on which a black and a red rectangle is drawn as soon as the user clicks on it. The Red Rectangle uses Color (200,255,0,0), so an Alpha value for transparency. The result can be seen here:
Link:http:\\www.bluecommerce.net\error.jpg
The code is:
Code:
private void pictureBox1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{
SolidBrush pen1 = new SolidBrush(Color.FromArgb(200,255,0,0));
SolidBrush pen2 = new SolidBrush(Color.Black);
Graphics Graph = userControl1.CreateGraphics();
Graph.FillRectangle(pen2,e.X - 50,e.Y - 50,100,100);
Graph.FillRectangle(pen1,e.X - 50,e.Y - 50,100,100);
}
As you can see, the red rectangle is NOT rendered in the vincinity of the Mouse cursor (the mouse icon), you can see the black Rectangle through it. This happens ONLY if the Red Rectangle has an alhpa value which is NOT 0 or 255. 0 and 255 work of course.
This error happens only on my computer and a similar one (both have Windows 2000 and a Matrox G450 Millenium graphics card), on another computer with WinXP and another graphics card the same code works perfectly.
All current drivers and ServicePacks fpr GDI, GDI+, Windows 2000, Visual Studio .NET 1.0 (Service Pack 2) are installed.
Now, I would like to know if the error occures because of the
a.) Graphics card
b.) Windows 2000
c.) Visual Studio .NET
d.) GDI+
e.) my fault?
Who already encountered something similar and knows help?
I've already spent hours in searching at msdn and google, but did not find anything.
Thank you very much for your help.
Kind Regards
Marcel
|
|
|
|
|
Don't know if it really has something to do with the problem you're experiencing, but you could take a look at the color depth of your display.
I remember having troubles with the TransparencyKey of System.Windows.Forms.Form when used with 32bit color depth. Using 16 or 24 bpp worked fine, using 32bpp required a workaround to get transparency to work.
So if you're using 32bpp you should switch to 24bpp and test whether the problem still persists.
Regards,
mav
|
|
|
|
|
Hi mav!
Thank you very much for your help, with 24 bpp, it works!
But of course, I have to use 32 bbp. Could you explain the workaround you used?
Thank you again for your help.
Kind Regards
Marcel
|
|
|
|
|
Of course I can, but I don't know if this will help you because the workaround is used to make parts of an image completely transparent and you said you wanted other alpha values than 0 or 255...
Anyway: The usual approach to make parts of a Form transparent is to assign a BackgroundImage and set the TransparencyKey to a color in your image. This works with color depth up to 24bpp, with 32bpp it seems to fail completely (i.e. you see your mask color, no transparency at all).
The suggestion some MS guy made was to first load the image, then make it transparent using Bitmap.MakeTransparent() and then setting the TransparencyKey to what you receive from calling Bitmap.GetPixel() for a pixel position you know to hold the mask color.
In code that means (used in the Load event handler of a Form ):
System.Drawing.Bitmap Img = new System.Drawing.Bitmap("Example.bmp");
Img.MakeTransparent(Img.GetPixel(0,0));
this.BackgroundImage = Img;
this.TransparencyKey = Img.GetPixel(0,0); Unfortunately, this approach doesn't work well for 24 or 16bpp displays
Perhaps you can come up with a solution by comparing the colors before and after making the bitmap transparent...
Regards,
mav
|
|
|
|
|
I'm using windows API to draw theme text onto a control. The text draws, but does not display the white shading that it should, I get only black.
I've tried with almost all types and value flags, but nothing changes. I get either thin, normal sized black text, or shaded black text (that looks bold).
I've used the flag for greyed out text as well, but still no luck.
I'll post some source code when I get home, but I don't have any now.
Any ideas why this happens?
Cheers
Cata
|
|
|
|
|
Say if you make a program that alows the user to "save a phone number, or Save a file". How do you save then load the file in the program? And create a directory and access it for the saved items?
I just got into c# when the summer started. So Thanks.
WartHog
|
|
|
|
|
There is no standard way - this is what programs do. You must decide the saving and loading routines.
If you want to write a text file, you can use a TextWriter derivative, like StreamWriter or simply use File.CreateText . When you read it, use a TextReader or simply File.ReadText (which returns a TextReader , an abstract class for other classes like StreamReader .
If you want to write binary files, you can use FileStream to both read and write.
If you want to store these attributes (like the phone number) in an object and serialize that to XML (a text format), then use XmlSerializer defined in the System.Xml namespace.
There's really a seemingly infinite ways of accomplishing this task and it all depends on what you want to do. This is a basic concept, however. I recommend that you read the .NET Framework SDK - especially the programming topics - and pick up a book or two on developing applications with .NET. If you read the .NET Framework SDK - and you should - the class documentation for those classes I mentioned above even have examples.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
|
It seems that specific books aren't usually recommended here (always the SDK's) but I lived in the C# Unleashed book (published by Sams) for the first six months of C#. Since then, I always have it handy along with Mastering Visual C# .Net which is published by Sybex. I know, the SDKs are free, but for the clarity, the $40 each was worth it!
Between the two, you will find how to do just about everything you need to do. In your projects, you will hit very specific advanced things you want to do (like change colors in a grid) which may not be clear. Then you visit the trusty The Code Project and pull up one of the many examples.
Good luck.
|
|
|
|
|
Thanks I will keep it in mind-its sounds really useful.
-WartHog
|
|
|
|
|
As a user keys text into a combobox I am adding or removing the contents of the list and reloading as needed. The problem is that the cursor jumps to the first character.
How can I stop this from happening or reset the cursor? Is there a better way to do this?
Thanks
|
|
|
|
|
Set ComboBox.SelectionStart to ComboBox.Text.Length to position the cursor after the text in a drop-down ComboBox (as opposed to a drop-down list).
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
In ADO.NET i want to get the row currently displayed in the windows form.The GetRow procedure , which is not intrinsic to .NET Framework , is contained in the Utility Functions region of the code ,do this work.
Anyone know how i can active/use GetRow() procedure ?
|
|
|
|
|
It looks like you need to study a C# programming manual a bit more while improving your English. (you are really living here in the US ???)
A form contains nothing but controls. It does not display anything but controls. So you have some type of control on your form which is displaying data....and some part of that data is related to a row in the database.
You do not mention what kind of database so let's start with an assumption that it is SQL Server. You need an SQLDataReader to read the data, you need to know SQL to format your dynamic request or a stored procedure.
How to execute each is dependant upon which way you get your data. A stored procedure requires you specify this in your connection and you then set the parameter name/value pairs. A dynamic sql requires you construct the SELECT statement.
So if you have a listbox, and a row is clicked which contains a key into your database, then you would do this:
1) Handle the click event and figure out the row selected.
2) Get the value and build the select based on the value in the listbox.
3) construct your reader and issue the Select.
I know of not language (not even VB) which has a GetRow() and you magically get a "row" from a database.
So as you can see....the answer to your still-unclear-question differs based on what control is on the form, what data is in that control, how it relates to the actual database, what database you are accessing, and finally which datareader you need. It requires Forms knowledge, SQL knowledge, database knowledge, C# knowledge. And if you think that GetRow() actually exists, then it shows that you have none of that knowledge.
This signature left intentionally blank
|
|
|
|
|
There is no public GetRow() mthod in any class in the .NET BCL, or ADO.NET, or the old ADO classes.
sasan56 wrote:
i want to get the row currently displayed in the windows form
A Web Form or a Windows Form can display MANY rows. It all depends on what control your using to display them. And what "Utility Functions" are you referring to? Who wrote the library your using?
Once again, you have to be MUCH more specific about your problem, the controls your using, and what you want to accomplish.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
There is a way, actually.
When you data-bind a record to a form or other control, you can get the current row from Control.BindingContext . It's important that you read the documentation for that property in the .NT Framework SDK documentation. Using a different binding context to retrieve a BindingManageBase from what you bound to the control in the first place will not work; you must bind to the exact same data source and, optionally, data member.
So, you're obviously binding to a DataSet or DataTable (note: it's far better to bind to a DataSet and set the DataMember of a control (if available) to the name of the table - it opens up more options).
So, lets say you bound your controls to a DataTable (since some don't have a DataMember default):
CurrencyManager cm = (CurrencyManager)this.BindingContext[myDataTable, null];
if (cm != null)
{
DataRowView rowView = (DataRowView)cm.Current;
if (rowView != null) return rowView.Row;
} Again, be sure to read about the BindingContext property and follow the related links. There's quite a bit of information about data-binding and binding contexts in the .NET Framework SDK documentation.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I am trying to use a Com object inside of code only I don't like referencing dlls or ocx's. Using AxImp.exe /source I was able to get the source code for the wrapper of C:\WINNT\system32\macromed\Flash\Flash.ocx file. When I add the source file to my project I get a namespace error
AxShockwaveFlashObjects.cs(21): The type or namespace name 'ShockwaveFlashObjects' could not be found (are you missing a using directive or an assembly reference?)
Could someone try this and see if they get the same error.
Also is there anyway to type in the code for a .Net control that I have in a separate class file and have the VS.NET IDE be able to manipulate it like a ToolBox control. I could have swore I have done that before.
Thanks,
Cyber
|
|
|
|
|
tlbimp.exe and aximp.exe do the same thing as referncing ActiveX controls in the Toolbox and as references from Add Reference - they both generate interop libraries (RCW's). That is the recommended practice.
Even if you add AxShockwaveFlashObjects.cs to your project, you still need to add the interop library Interop.Flash.dll (or whatever it is called) to your project. aximp.exe creates to interop assemblies - one that contains the definition of any ActiveX controls that derive from AxHost , and one that contains the RCW for the typelib (type library). Both are required.
If you want do it the manual way, you must still reference the latter interop library mentioned above. You're duplicating code, though, if you reuse the ActiveX control in other projects. That's why signing the interop assemblies and using them across your projects is a much better idea - granular control.
If you want the control you've compiled into your assembly to be in the toolbox, then after you've compiled your project custom your toolbox (right-click on the toolbox) and browse to your assembly (it won't show up in the list unless you've added the necessary registry key, and for a project in development that's silly - especially in the target directory; at least copy it to a common path). When you click OK after browsing for it, you can check which components (including controls) you want to add to the toolbox.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Is there a pre-existing class/method in .NET or does anyone know of code that will count the number of unique format items in a string (i.e. how many parameters are required.)
In other words, passing "This is {0} a {1} test {0} string" to this method would return 2. (If I could also verify that the string is well formatted, that would be a big plus.)
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|