|
I think you have 2 ways to do waht you want :
1) make a button in the corner of the window whitch has the dataGrid that updates the database with the contnets of the grid
or
2) catch every changed row in the dataGrid and update it in the database after the complete change
I would recommand option 1 because when a mistake is made it can be undo.
I hope you know something about asp.net in order to do what I wrote...
ps: when a value is changed in a dataGrid, the dataTable that is the source is modified too.
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
would u provide me the code here. I visited the site but did not find any thing related.
it is better if someone provide me the C# code with the MS Access.
|
|
|
|
|
This is my code to display the table into the datagrid.
private void btnShow_Click(object sender, System.EventArgs e)
{
try
{
//set SQL query
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM KeyAnswers";
//clear dataset
dataSet1.Clear();
//Fill dataset with information
oleDbDataAdapter1.Fill(dataSet1,"KeyAnswers");
//bind datagrid
dataGrid1.SetDataBinding(dataSet1,"KeyAnswers");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
finally {
}
}
This is when I click the show button.
Now I want to create a "Update" button . what should be the code?
Should I update the whole table wheras only one record has been changed?!!
waitting.....
thanks
|
|
|
|
|
pleasehelp me
|
|
|
|
|
I think that when you click the show button the call of SetDataBindingis is not necesarry.
And at the update you code should look like this :
<br />
private void btnShow_Click(object sender, System.EventArgs e)<br />
{<br />
...<br />
oleDbDataAdapter1.SelectCommand.CommandText = "SELECT * FROM KeyAnswers";<br />
<br />
OleDbCommandBuilder cb = new OleDbCommandBuilder(oleDbDataAdapter1);<br />
...<br />
}<br />
<br />
private void btnShow_Click(object sender, System.EventArgs e)<br />
{<br />
try<br />
{<br />
oleDbDataAdapter1.Update(dataSet1,"KeyAnswers");<br />
MessageBox.Show("Changes saved successfully!");<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show("There was an error while saving the changes : ex.ToString());<br />
}<br />
<br />
finally {<br />
}<br />
}<br />
PS: my code is not 100% correc in the way i haven't got an .net compiler right now, but that is the algorith you shoul use.
I hope you understand...
By the way... visit http://nehe.gamedev.net[^]
|
|
|
|
|
I have a C# Class Library Project in VS 2003. How do I import and make use of a .tlb file to that project?
_____________________________
...and justice for all
APe
|
|
|
|
|
Hi every body , from day i have a problem that i can't solve , how i can pass a STRING variable by using a matlab program dll .
The document 1,2,3 ways offer just a double variable
Plz i need it ,
thx
|
|
|
|
|
Not sure at all what you are asking, but if you just need to convert a string to a double try:
double myDbl = double.parse("123.45");
|
|
|
|
|
Hi all,
I'm resizing an image in C# and when I use InterpolationMode.HighQualityBicubic and SmoothingMode.AntiAlias (and many other combinations) I get a 1px wide border all around the image. This is ok for the project I'm working on expect for the bottom border. I have tried to overcome this by drawing the pixel above the bottom border over it, like this:
<br />
for ( int i = 1; i < width; i++ )<br />
{<br />
bitmap.SetPixel( i, height, bitmap.GetPixel( i, height - 1) );<br />
}<br />
where width and height are bitmap.Width and bitmap.Height, respectively.
But I'm obviously missing something since this isn't working. Any ideas?
|
|
|
|
|
Bicubic interpolation uses the values of the surrounding pixels, it's possible the GDI+ implimentation uses the values of the pixels on the other side of the image to interpolate the edges.
You should never use GetPixel/SetPixel unless time is not critical.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Hi, thanks for the answer. This doesn't only happen with Bicubic interpolation though. What are my options if I don't want to use get/setpixel? In this particular project, the images are tiny and time is of no importance, but I would like to know the better alternatives.
best regards,
FAC
|
|
|
|
|
Read my image processing articles for info on how to lock/access/change bits of a bitmap.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
So, I have this WebBrowser control that everyone knows about, and I have popups disabled, per NewWindow2() event, which is really cool. However, there do exist certain sites that use windows.alert("message digest") that doesn't count as a pop up, since it opens a messagebox window instead of another webbrowser window . So I want to disable scripting in my control. The best answer I've found so far was "look at MS's WALKALL example (http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/samples/internet/browser/walkall/default.asp)." Well aside from the fact that MS is really good at using unmanaged c code that I have almost no experience reading, they also excel at providing really crappy documentation . So basically I've read the code over and over and all that's done is hurt my head . Does anyone know how to disable scripting in a webbrowser control ***IN C#***?
|
|
|
|
|
I am writing an application that monitors users' bandwidth and disables their network connection if they have downloaded/uploaded to much data. For users with a DHCP IP address this is simple but I am having troubles with people with Static IPs. The best idea I could come up with is to just disabled the network card, but I don't know how to.
Can anyone give me some ideas?
Thanks,
Eric Sanders
Purdue University
|
|
|
|
|
Hi all,
I'm missing a simple disable property bit which prohibits the change of data in all input controls.
control.enable = false;
Is there an other way than to jump to an unvisible dummy-control when enter/change/cut&paste... is triggering ?
It would be useful to make an expansion of the form/controls base class from which I can inherit all input controls.
Does someone have an idea how to do that ?
Thanks for your ideas !!
Regards
Frank
|
|
|
|
|
You're right. It's a missing feature what would be nice. Some controls have a ReadOnly property which you could use. Making a base class will not be so easy. You could define an interface and try to inherit from every control you need and implementing this interface. But you will nevertheless have to implement the ReadOnly behaviour yourself in most controls.
|
|
|
|
|
Hi. I’ve managed to call a unmanaged c++ dll function into a C# project using the DllImport attribute. Now I like to Import a hole class that my old dll exposes. Is that possible and how do I do that?
_____________________________
...and justice for all
APe
|
|
|
|
|
Heya!
I'm using databinding to an object. I'm binding a txt box to the object's Name property. The Name property is a string of length no longer than 10 chars. In the Name property's set accessor method, I check if the string value's length > 10. If it is I throw a FieldLengthException(my own).
The problem:
In the UI I want to catch this exception but I'm not sure where this exception can be caught (or for that matter where to put the try clause)
Eg.
<br />
public class Person<br />
{ <br />
private string _Name = "";<br />
<br />
public string Name<br />
{<br />
get { return _Name; }<br />
set <br />
{<br />
if (Name.Length > 10)<br />
throw new FieldLengthException("Field restricted to 10 characters");<br />
else<br />
_Name = value;<br />
}<br />
}<br />
}<br />
<br />
Person p = new Person();<br />
<br />
Binding bName= new Binding("Text", p, "Name");<br />
tbName.DataBindings.Add(bName);
<br />
|
|
|
|
|
|
Sorry please help me out
I got this error when doing SQL INSERT.
"Object reference not set to an instance of an object."
This was my coding:
string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
string desc = txtMailing.Text;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\testing_K_\db1.mdb");
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter oleDbDataAdapter1 = new OleDbDataAdapter(cmd);
oleDbDataAdapter1.InsertCommand.CommandText =
"INSERT INTO Mailing (MailingField)" +
"VALUES ('"+ desc +"')";
//open the bridge between the application and the datasource
con.Open();
oleDbDataAdapter1.InsertCommand.Connection = con;
//execute the qurey
oleDbDataAdapter1.InsertCommand.ExecuteNonQuery();
//close the connection
con.Close();
The underlined sentence is the error. Please give me tips or advice to solve this.
Thanks
fire85.
|
|
|
|
|
Hi.
To make an update you do not need the data adapter.
Write like this and you will be happy:
<br />
SqlConnection con = ...<br />
try {<br />
using (SqlCommand cmd = new SqlCommand("INSERT ...", con)) {<br />
cmd.ExecuteNonQuery();<br />
}<br />
catch (SqlException ex) {<br />
}<br />
if (con != null) {<br />
con.Dispose();<br />
con = null;<br />
}<br />
By the way, using is nice, it runs Dispose() on your command-object automatically.
/M
|
|
|
|
|
Yeah Thanks alot
It works
fire85.
|
|
|
|
|
The SqlCommand parameter in the SqlDataAdapter constructor is for the SelectCommand , not the InsertCommand . But the other response is correct, you don't need the SqlDataAdapter . The SqlCommand.ExecuteNonQuery call is enough.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Sorry i am a newb to programming, cant get the meaning of what you trying to say.
Is there any article or book that clearly explain about database linking??
Please introduce to me Thanks
fire85.
|
|
|
|
|
You need an SqlCommand object to represent execute any SQL statement on the database. The SqlDataAdapter is only a bridge that connects the data obtained from the database by executing a SELECT command, to a DataSet or DataTable (which can hold data on which you can work, without being connected to the database.)
The SqlDataAdapter can also contain other commands (specifically, one INSERT , UPDATE and DELETE ) that will be used when you ask it (the data adapter) to save the changes you've made to the offline data (DataTable or DataSet ) to the actual database.
So, it works like this:
1. You create a SqlCommand object representing your SELECT statement (it can be a stored procedure wrapping a SELECT statement.)
2. You create a new SqlDataAdapter object and pass it the SELECT statement.
3. You create an empty DataTable (or DataSet )
4. When you call myDataAdapter.Fill(myDataTable) , the SELECT statement is executed in the database, and all the returned records are stored into the myDataTable object.
5. You start working with the data in the myDataTable object. You can add, modify or delete records offline, and your changes will not be saved in the real database. At this point you are not connected to the database.
When you want to update the database with the changes you made to myDataTable , you follow these steps:
1. Create SqlCommand objects for the INSERT , UPDATE and DELETE queries.
2. Assign those command objects to the InsertCommand , UpdateCommand , and DeleteCommand properties of SqlDataAdapter object (myDataAdapter here).
3. Call myDataAdapter.Update(myDataTable) .
4. The data adapter will look at each record in myDataTable and see what kind (if any) of modification it has had, and execute the appropiate command (INSERT if the row was added, UPDATE if it was modified, or DELETE if it was removed.)
So, to your question. First see this[^] topic in MSDN. Can you see that the constructor's argument is named selectCommand ?
When you pass your SqlCommand (which does represent an INSERT query) to the constructor, it's taken as the SELECT command. So, when you try to access it through the InsertCommand property, it naturally is null, since you have not initialized it to something. A quick fix would be to set the InsertCommand to your cmd object before trying to set its CommandText:
<code>OleDbDataAdapter oleDbDataAdapter1 = new OleDbDataAdapter(cmd);
oldeDbDataAdapter1.InsertCommand = cmd;
oleDbDataAdapter1.InsertCommand.CommandText =
"INSERT INTO Mailing (MailingField)" +
"VALUES ('"+ desc +"')"; But as you saw from the above description of data adapters, since you are executing a query and you don't get any results back, a DataAdapter is overkill (actually you are not using it, you just use it to hold a command object which you then execute directly.) So, get rid of the data adapter:
string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
string desc = txtMailing.Text;
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\testing_K_\db1.mdb");
OleDbCommand cmd = new OleDbCommand();
cmd.CommandText = "INSERT INTO Mailing (MailingField) VALUES (?)";
con.Open();
cmd.Parameters.Add("param1", desc);
cmd.ExecuteNonQuery();
con.Close(); As you can see, there's no OleDbDataAdapter (I just noticed you are using Access and not SQL Server, but all the above description equally applies.)
Note the bold text in the code above. Your code as you had it contains a serious security vulnerability (it's vulnerable to SQL injection attacks, see this article). The code I provided you contains paramters, which, for one thing prevent this[^] type of attacks, but also avoid problems if somehow there's a single quote (' ) in the desc variable.
I hope this helps!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|