|
explaining how to open up a connection etc. would maybe be a lot of text.
Go to MSDN[^] and do a search on "dataset", "datareader", "dataadapter", "oledbcommand", "sqlcommand", "connection string"
that should get you started...
Hope this helps.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
hi
I need only example how to add values from textbox to existing database
see my code
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
SqlConnection db = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\c#\LoginControl1000\ErikSchmidt\TestLoginControl\Database1.mdf;Integrated Security=True;User Instance=True");<br />
try<br />
{<br />
db.Open();<br />
}<br />
catch{}<br />
if(db.State==ConnectionState.Open)<br />
{<br />
using (SqlCommand sql = db.CreateCommand())<br />
{<br />
sql.CommandText = "INSERT INTO tabela (id,nazwa) VALUES (@zmienna1,@zmienna2)";<br />
sql.Parameters.Add("zmienna1", "3");<br />
sql.Parameters.Add("zmienna2", "wss"); try<br />
{<br />
}<br />
catch{}<br />
}<br />
}<br />
<br />
}
what Im doing wronge that data is not save in database ?
|
|
|
|
|
sql.ExecuteNonQuery() should not be commented.
Also make sure that the insert statement is correct and the connection openen correctly...
Here's an example of the insert method I use in my component:
<br />
public int ExecuteInsert(string stmnt){<br />
DB_STATUS dbstat = DB_STATUS.UNDEFINED;<br />
try{<br />
Sqlconn.Open();<br />
dbstat = DB_STATUS.CONNECTION_OK;<br />
try{<br />
SqlCommand Sqlcmd = new SqlCommand(stmnt);<br />
Sqlcmd.Connection = Sqlconn;<br />
SetNrOfRowsAffected(Sqlcmd.ExecuteNonQuery());<br />
dbstat = DB_STATUS.EXECUTE_OK;<br />
}
catch(Exception e2){<br />
errormessage = stmnt + " " + e2.Message;<br />
dbstat = DB_STATUS.EXECUTE_FAILED;<br />
}
Sqlconn.Close();<br />
}
catch(Exception e1){<br />
errormessage = Sqlconn.ConnectionString + " " + e1.Message;<br />
dbstat = DB_STATUS.CONNECTION_FAILED;<br />
}
return (int)dbstat;<br />
}
hope this helps.
|
|
|
|
|
thx but this not help
Could You make for me project like in my printscreen,and send it to me ? I need to look it closer,analize...lecture doesnt helps me,
|
|
|
|
|
Are you completely nuts?
NO!
I never did, will not and will not ever make a project for someone else!
I told you were to look, I provided you with a sample, the only thing I can advice you is to buy a book and start reading.
I'm sorry I couldn't be more helpful to you, but believe me, nobody in CP will make something for you, they'll only provide help.
|
|
|
|
|
pawcio_be wrote: Could You make for me project like in my printscreen,and send it to me ? I need to look it closer,analize...lecture doesnt helps me,
Kid, this is not "www.homeworksforfree.com" this is codeproject. Ok. How much are you gonna pay me if I send you the code?. huh? If you are getting help for free, first be greatful to that before starting your "orders".
pawcio_be wrote: lecture doesnt helps me
That's your mistake. Go back to school and learn to learn from lectures.
I guess you've landed up in the wrong site.
Code-Frog:So if this is Pumpkinhead. Time for him to run and hide. It's an interesting thought really.
|
|
|
|
|
Hi,
I would like to generate a bigger ouptut texture from the small sample. I lock bits and copy them to byte array. Next I copy bytes to the output byte array and again lock bits and create output Bitmap. Everything works properly when OutputImage.Width % 4 = 0, if output image width (in pixels) is diffrent than 0 I get strange image! I tryed to make something with PixelFormat, but it didn't give any effects.
thanks for any help
|
|
|
|
|
Images have logical dimensions (width and height), and their in memory representation has
physical dimensions. They typically have a "stride", which equals the number of bytes (or
pixels?) you should advance in order to get to the next scanline. Assuming all numbers
are positive, stride>=width will hold true, stride==width may or may not be true.
See also BitmapData.Stride
Luc Pattyn
|
|
|
|
|
Hi,
How is it possible to use trusted connection for an Intranet site?
Intranet is using a webservice which is hosted on a web server on LAN.
This is the connectionstring that I am currently using for the intranet website in the company LAN.
<value>Data Source=SQLMachineName1\MSQL_DEV;Initial Catalog=DBdatabaseName;Persist Security Info=True;User Id=WebUserAccountName;Password=password;
I would like to use this connectionstring instead so that I can have more control over the logged in users.
If I do use this connectionstring the error it gives is:
Login failed for user (null). Not associated with a trusted sql server connection.
<value>Data Source=SQLMachineName1\MSQL_DEV;Initial Catalog=DBdatabaseName;Integrated Security=True
|
|
|
|
|
the problem is in your server rights, not in your code...
enjoy the code with you is my priority,
Blaise Braye
|
|
|
|
|
For information I am working with a bindinglist as datasource :
see the objectview project here: http://sourceforge.net/projects/objectviews
OK, i want to be more explicit,
It's really easy to work with them both.
But in my context, I have keys collections.
So I wanted to have an inputBox which would appear when the object bounded contains a key.
Of course this inputBox is asking a unique key for the new object (row...)
The idea is that once the object is created, the user is not allowed to edit the key column (which has been set in read only mode at generation time).
Currently, how am I working?
I have a control which extend the DataGridView and which is composed of an ObjectView
let's call them dgvExt and collection.
in dgvExt i have my implementation to generate columns, to know which are keys,...
in dgvExt I have a EventHandler which listen the collection.RowAdding event.
this event is sending in parameter the innerobject (null at this step) that will be bounded to the row.
so.. In my EventHandler, I am creating my self the new object if it contains keys.
and I set it in the parameter sent by collection.
maybe you will understand why I want to work like this when you'll this code:
void collection_RowAdding(object sender, InstanceEventArgs e)
{
InputBox ib;
Type type = typeof(ConfigurationElement);
if (e.Type.Equals(typeof(KeyValueConfigurationElement)))
{
ib = new InputBox("Insert the key", "Insert key");
if (ib.ShowDialog() == DialogResult.OK)
e.Instance = new KeyValueConfigurationElement(ib.EnteredText, "");
}
if (e.Instance != null && e.Instance is ConfigurationElement)
{
MethodInfo init
= typeof(ConfigurationElement).GetMethod("Init", BindingFlags.NonPublic | BindingFlags.Instance, null, new Type[] { }, null);
init.Invoke(e.Instance, new object[] { });
}
}
In fact the problem is not what I want to do here,
but how to cancel the adding process in dgvExt efficiently?
Why to cancel? the inputBox allow the user to cancel... but I don't want a row with empty key...
this problem is really hard for me... certainly I am just not on the right way.
enjoy the code with you is my priority,
Blaise Braye
|
|
|
|
|
The database is on server(sql server 2000).
The application run on the client pc's.
How can i update the data in the application when the data on server has been changed.
|
|
|
|
|
|
Thanks for the reply.
The application is a windows application is there a difference?
|
|
|
|
|
have a look at also
http://www.15seconds.com/issue/041006.htm[^]
I couldn't give you the answer to your question because I simply didn't try it.
For this kind of applications, I am using transactions
enjoy the code with you is my priority,
Blaise Braye
|
|
|
|
|
Hi Capuano,
You have to implement/design a sort of "push - pull" mechanism. You have identify what is changed ( tablesize, tablecontent, indexes .. etc ) and monitor that. Then push out a message to the users saying what has changed, or invoke a method that can update the clients with what ever you want. It not easy to give you a hard and fast anwser because your post lacks the information required to send you down the right path ( if there is such a thing )
Cheers,
|
|
|
|
|
The database is on server(sql server 2000).
The application (Windows application)run on the client pc's.
How to use the SqlTriggerContext to update the data in the application when data on server has been changed?
|
|
|
|
|
how to create a web service project ? i have to administrate a an application remotely so i need ro create a web service ? please who has a answer reply urgently
|
|
|
|
|
|
I have created a .net 2.0 windows application.
Trusted connection to connect to sql server.
Using sql server System_User, the application gets the loginname for the user in sql server.
Now I have created webservices to be used in this project.
It seems that I can not use my existng method (Trusted connection) to get the loginName of the user.
So in sql server, created a webuser account.
Everyone now is using the system using the webuser account.
But, this way I do not know exactly which user is using the application because all I see is webuser hitting the database through the application.
How do you suggest I log the users?
I was thinking may be I should create roles on the network. i.e. NormalUsers, managers, chairmen, etc,...
Then add the appropriate users to these roles on the network.
I can then create a login screen.
Windows application can then find the user identity. This user can then be traced from the users table in sql server and get it's ID. ID can be used to be inserted into the Audit table.
What do you think please?
THnaks
|
|
|
|
|
If it's an internal network and you have a domain, I would just use integrated security. To handle database access you can either impersonate a user temporarily, use a SQL server login, or give the users themselves access to the database. That prevents you from having to use a login screen but still gives you access to their identities.
In case you're not on a domain, you'll have to create a login page and roles and manage all of that. There should be plenty of examples out there on how to do that.
|
|
|
|
|
Frnds,
i m working in C#.
My client wish to have a clored text in a texbox if my textboxes are disabled .
Can anybody suggest me any method to solve this problem of mine.
reply me via email.
Thanks
Sumit Kumar
sumit.professional@gmail.com
|
|
|
|
|
You need to enable the textbox to change the text, then disable it again. You can set the text color as a property on the textbox, I thought.
sumit_kumar wrote: reply me via email.
No. Set up your account to use your address, and you'll get no spam from CP, no spam because people won't be able to trawl the site and find your address, and an email when people answer.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Christian,
Good anwser, but I do have a side note though
The grayed out bit is a standard behaviour on a disabled textbox. This cannot be changed. However, there are some ways around it though.
1. Override the OnPaint event of the textbox.
{
SolidBrush drawBrush = new SolidBrush( ForeColor ); //Use the ForeColor property
// Draw string to screen.
e.Graphics.DrawString( Text, Font, drawBrush, 0f, 0f ); //Use the Font property
}
Note: You need to set the ControlStyles to "UserPaint" in the constructor.
public MyTextBox()
{
// This call is required by the Windows.Forms Form Designer.
SetStyle( ControlStyles.UserPaint, true );
InitializeComponent();
}
or something like that.
2. ( one of my favorites and less complicated ). Set the textbox to readonly and change te colors. This will preserve the textbox properties, allowing you to do anything with it that you want, and still mimic a 'disabled look'
private void OnClickButton(sender object, EventArgs e)
{
myTextbox.ReadOnly = true;
myTextbox.Forecolor = System.Drawing.Color.Red;
myTextbox.Backcolor = System.Drawing.Color.Gray;
}
Cheers,
|
|
|
|
|
I thought you could set the Text property even when the textbox was disabled?
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|