|
This is an exception thrown by .NET - not your file. Your SQL query is returning results that violate the foreign key constraint. That is, if you have relationships set up in your DataSet (which appears to be the case) and you insert rows into the foreign table, then the foreign keys must exist in the primary table.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Is there a way to control instantiation of a class/object in c#?
I am trying to replicate the functionality of VB6 which allows you to specify whether the class can be instantiated by anyone, or whether it can only be used by other classes in the same project. What this would allow is the class being instantiated, and even returned by a "factory" construct, other code could USE the class, but it couldn't be instantiated elsewhere.
I've tried using "internal" in C#, but perhaps I'm using it wrong - or this doesn't really do what I'm wanting to do.
However, c# seems to insist that if a class is out there, it can be created anywhere.
Is there a way to do this?
Thanks.
|
|
|
|
|
The following modifiers can be used with classes:
public - Access is not restricted.
protected - Access is limited to the containing class or types derived from the containing class.
internal - Access is limited to the current assembly.
protected internal - Access is limited to the current assembly or types derived from the containing class.
private - Access is limited to the containing type.
So there is nothing wrong with using "internal", just you can instanciate the class from anywhere in the assembly.
|
|
|
|
|
This is accomplished by placing the appropriate access modifiers to both the class and the constructor.
<p>
public class MyClass
{
public MyClass() { }
}</p>
<p>
public class MyClass
{
internal MyClass() { }
}</p>
<p>
public class MyClass
{
private MyClass() { }
public static MyClass CreateInstance()
{
return new MyClass();
}
}</p>
|
|
|
|
|
hi,
i'm searching a way to retrieve a DateTime in a DataTime sql column via a datareader.
i' ve got something like this :
myCmd = new OdbcCommand( "SELECT (pretime) FROM pretable WHERE rlsname = "pwet",myConnection );
OdbcDataReader odr = myCmd.ExecuteReader();
it return me, a single cell with the datetime i want into.
but i don't manage to retrieve ths value.
if someone could help me
thx a lot
|
|
|
|
|
I hope I'm understanding the question correctly.
I think what you want to do next is something like this...
datetime dtmTime = odr.GetDate(0)
You may also want to check that the field is not null before calling the GetDate method.
|
|
|
|
|
yep i've try your solution, but it return me an error like :
System.invalidoperationexception : No data exists for the row/column.
however i check this : if(odr != null) and it enter in the if but when it execute DateTime dt1 = odr.GetDateTime(0);
i get the error :/
i don't know wht to do :/
|
|
|
|
|
You don't check if the reader is null, but if the column at index 0 is DBNull :
DateTime dt;
if (!odr.IsDBNull(0))
dt = odr.GetDateTime(0); FYI, there's no need to check if the odr variable is null. If an OleDbDataReader can't be returned for some reason, an exception will be thrown.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
thx =)
now i get an error here -> if (!odr.IsDBNull(0))
and its the same error like before :/
|
|
|
|
|
What error? Be specific.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
My big mistakeeeeeeeeeee lol
i was not searching for the right string in the sql db ^^
so there is no problem lol
thw a lot
|
|
|
|
|
Hi guys
Gotta question, I need to access a shared folder in a network, which file to be played in windows media player in an aspx page. It returns me the following error on the windows media player:
0xC00D1196, Condition : 0X00000000 Incorrect user name or password
Does anyone know how to set the username and password for a network share in windows media player? (Code behind page is using C#)
Cheers,
Rico
|
|
|
|
|
First: you have to post it to ASP.NET forum.
What kind of authentication have you used in your web application? You can use Impersonation or give the proper privilage to ASP.NET account to read in network.
Mazy
"One who dives deep gets the pearls,the burning desire for realization brings the goal nearer." - Babuji
|
|
|
|
|
First:
I have posted the same question in ASP .NET forum, but no one reply, so I try here. =)
Second:
I've tried using WNetAddConnection2 function from the windows API. It does connect to the network, but the thing is the windows media player was a different Object (I use the HtmlTextWriter so that the windows media player object can be treated as Web control), so when I set the URL with the IP address of the network (and the folder name), it doesn't recognize / get the connection that I've already created with WNetAddConnection2 in the application. Therefore it gives the following error:
0xC00D1196: Incorrect user name or password<br />
The user name or password may be incorrect. <br />
To access a file that is located on a secure network, you must supply a user name and password for the network domain. <br />
Ensure that the user name and password that you are using are spelled correctly and are recognized by the network domain. <br />
It is not sufficient to use a user name and password for a local system account, which provides access to your computer but not the network.<br />
<br />
Error ID = 0xC00D1196, Condition ID = 0x00000000
Is there anyway to set the username and password to windows media player? (Like try to open a network file from a windows media player, how to prompt the username and password?)
Thanks in advance, hopefully you can help me, I've tried to post this everywhere (even in windows media newsgroup, wmtalk) , but no one can help me..
Regards,
Rico
|
|
|
|
|
How would i exposs a class library as a COM object. i look through the SDK Docs and still a little lost.
[ ...what to put in here? ]
public class MediaStatusSink : IMediaStatusSink
{....
}
I just need help setting up the class attributes,
here is what im trying to do:
A sink is a COM component that supports the IMediaStatusSink interface and is registered as a member of the CATID_MediaStatusSink {FCB0C2A3-9747-4C95-9D02-820AFEDEF13F} component category.
in the registry editor at
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Component Categories\{FCB0C2A3-9747-4c95-9d02-820AFEDEF13F} i have:
(default) REG_SZ (value not set)
409 REG_SZ Media Status Sink
modified 16-May-21 21:01pm.
|
|
|
|
|
You create a new GUID using the GUID generate in the Tools menu, or the uuidgen.exe, or whatever preferred method you want. Then use the GuidAttribute on your class. Typically, you never change this GUID. You also attribute any class interfaces with a different GUID and after publishing your interfaces (i.e., releasing your code, etc.), never change it. Instead, inherit from that interface with a new one and a different GUID, and implement that as the first interface instead making it the class interface.
The GUID you're looking at is a category ID. I'm not sure what you're trying to do, but if you simply want to implement the interface, you can use any GUID you want. If you're trying to manually interop an existing class, then you can use oleview.exe to find the class and get its CLSID, which is what you'd put in the GuidAttribute on your class declaration.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Could someone please post a step by step tutorial on getting an access database to work on a asp.net form with c#? I have read a few things like changing the <appsettings> and then making a connection string. I'm still very confused. I thought that it was like winforms you simply drag the oledbdataadapter over to the form then generate a dataset and then in the code simply fille the dataset with oledbdataadapter1.fill(dataset);
I haven't a clue how what needs to be changed in the web.config file. I have a book but it assumes i use sql server. Unfortunate for me I don't have the money to buy an sql server so i'm forced to use what i have access too which is office access xp. Once again if you could direct me to a site that assumes i know nothing about c# webforms that would be great. Or simply make a webform with a dropdown menu that gets some values from a mdb.
thanks for your time. i constantly get the database is in use or you don't have permission to use it when i try. if you need some code examples of what i'm doing that would be fine just let me know. I would prefer a tutorial though so i don't get totall confused. Oh wait I already am totally confused.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
I've already told you, and this is very easy to do. In your Web.config file, put your connection string in the <appSettings> section:
<configuration>
<appSettings>
<add key="ConnectionString" value="your connection string"/>
</appSettings>
</configuration> When you need to create your connection, use:
string connString = ConfigurationSettings.AppSettings["ConnectionString"];
if (connString != null)
{
OleDbConnection conn = new OleDbConnection(connString);
} This allows you to change your connection string at any time so that your project is also easy to deploy.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath,
Sorry for not grasping it the first time you posted the answer. I was still confused but finally figured out what i was doing wrong. Its working now. Do you recommend a book for someone like myself that is just getting into c# and asp.net? I'm as you can tell stumbling over the simple things and really would like to learn. I just hope I don't get on your nerves or anyone elses for that matter for not understanding. Thanks for your patience with me on my quest for knowledge in c#.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Just read through the articles and class documentation in the .NET Framework SDK. That's the best way to learn. There is books out there, but I can't recommend any since all I did was read through the SDK and got a sense of where everything was and what they do, read articles on sites like CodeProject (though there wasn't too many back in the 1.0 beta days), examined a lot of the MSIL in the .NET FCL assemblies, and just wrote lots of various projects trying different things.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I finally got it populating the dropdownlist from the dataset. I do have a question though for some reason i can't figure out why the index is always 0 regardless of what i select. What i'm trying to do is select an index in the dropdownlist and then have it display some information in the textbox2.
public DataSet dataset;
private void Page_Load(object sender, System.EventArgs e)
{
string datapath = Server.MapPath("bin/csharp.mdb");
string connString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]+datapath;
if (connString != null)
{
oleDbConnection1 = new System.Data.OleDb.OleDbConnection(connString);
}
oleDbConnection1.Open();
OleDbDataAdapter dataadapter = new System.Data.OleDb.OleDbDataAdapter("select * from Csharp",oleDbConnection1);
dataadapter.Fill(dataSet11,"Csharp");
oleDbConnection1.Close();
DropDownList1.DataTextField ="Help";
DropDownList1.DataValueField="Help";
DropDownList1.DataSource = dataSet11;
DropDownList1.DataBind();
}
private void Button1_Click(object sender, System.EventArgs e)
{
TextBox2.Text = dataSet11.Csharp[DropDownList1.SelectedIndex].Information.ToString();
}
for some reason as i mentioned before the page refreshes on the button push but it always reads whats in index 0.
thanks for the help and patience with me.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Make sure you've enabled the ViewState for the control and/or page is enabled. Also, don't call ToString until after you've checked for null or use a try/catch block, though easy problems like this can easily be solved using conditionals and would result in better performance than throwing an exception, which is more expensive.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi folks,
Consider an SQL Server table that has got a PK (auto-identity column), which
has been referenced by another table as a FK. Then imagine 2 DataTables that
has been created to refer to the above-mentioned SQL Server tables, either
partially or completely. I need to know how can I read/write these
DataTables from/to those DataSources using the OleDbDataAdapter.
It goes without saying that when you insert a row within the first source table, you'll get an IDENTITY that has to be referenced by the second table as the FK's value. The thing that I cannot understand is that how I can possibly interact with these 2 DataTable(s) through the OleDbDataAdapter and how to map DataSource-DataTable columns to each other as well as how to get the newly added IDENTITY and insert it in the second DataTable.
Any sample would be highly appreciated
Thanks in advance,
Mehdi Mousavi - Software Architect [ http://mehdi.biz ]
|
|
|
|
|
First, don't use the OleDbDataAdapter for SQL Server! Use the SQL Server-specific classes in the System.Data.SqlClient namespace. They exhibit much more functionality and provide features that the generic OLE DB providers can't provide (at least in an abstract manner).
Second, use a typed DataSet , or construct one programmatically at runtime (not fun). You can create an identity column in one of your tables. When you insert a row into that DataTable , the column value is incremented to the next identity using your incremental step. This allows your FK column to reference the identity PK. This is easy to do.
The trick in a multi-user database-driven application is when you use that DataSet to update the database using SqlDataAdapter.Update . You should read the article, Inserting relational data using DataSet and DataAdapter[^]. Basically, your InsertCommand should also include a SELECT statement to make sure the DataSet is updated appropriately. The relationship that would exist in the DataSet for the PK/FK would update the FK with the PK value that was actually used when the row was inserted.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath Stewart wrote:First, don't use the OleDbDataAdapter for SQL Server!
We might change the Database engine later from SQL Server 2000 to Oracle 9i, and that's why we tried to use the OleDB Data Provider.
Heath Stewart wrote:
Second, use a typed DataSet, or construct one programmatically at runtime (not fun).
I don't see anything fun in this quote. I've never ever used an untyped DataSet, since it has got many drawbacks...
Heath Stewart wrote:
You should read the article, Inserting relational data using DataSet and DataAdapter[^].
Thanks a lot, I read the article and it will certainly solve my problem after two damn weeks of trying to post the same question here and there.
I do really appreciate your help.
Thank you for your time,
Mehdi Mousavi - Software Architect [ http://mehdi.biz ]
|
|
|
|