|
Hi there,
When I use the following code below I get and error called , "concurrency violation" and the database is not updated.
I am able to connect and retrieve data. but I cannot update the data from the datatable of dataset.
I am new to datagridview and datasets.
I am using Mysql 5.0 and Mysql connector .NET 5.1.2
I read many articles on updating the dataset and almost tried everything , but It does not work, I can update to Mysql database using update commands. But I want to use Dataset or dataadapter update to make it more simpler.
public partial class Form1 : Form
{
DataSet ds = new DataSet();
MySqlDataAdapter da;
DataTable dt = new DataTable();
string tabname;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
CreateMySqlCommand();
}
// Connecting to db and filling the datagridview with data.
public void CreateMySqlCommand()
{
MySqlConnection myConnection = new MySqlConnection("Persist Security
Info=False;userid=root;password=XXXX;database=test;server=terrain");
myConnection.Open();
MySqlTransaction myTrans = myConnection.BeginTransaction();
string mySelectQuery = "SELECT * FROM patient_master";
MySqlCommand myCommand = new MySqlCommand(mySelectQuery,
myConnection,myTrans);
da = new MySqlDataAdapter(mySelectQuery ,myConnection) ;
MySqlCommandBuilder cmdBldr = new MySqlCommandBuilder(da);
da.Fill(ds);
dt = ds.Tables[0];
DataRow row;
row = dt.Rows[0];
int lirow = dt.Rows.Count;
string mrno = row["MRNO"].ToString();
string patname = row["GIVEN_NAME"].ToString();
dataGridView1.DataSource = ds;
dataGridView1.DataMember = ds.Tables[0].ToString();
tabname = dt.TableName;
int y = 0;
foreach (DataGridViewRow ro in dataGridView1.Rows)
{
if (y % 2 == 0)
ro.DefaultCellStyle.BackColor = Color.Red;
y++;
}
}
// code on the button to update the datadapter
private void button1_Click(object sender, EventArgs e)
{
da.Update(ds, tabname);
}
}
}
|
|
|
|
|
I have the same problem. Any solution?
|
|
|
|
|
Hi all,
I develop one application in c#.net 2.0 and i want to use Windows Vista cursor "aero_busy.ani".
My Operating system is Windows 2000 Server. So can i use that cursor?
Is there any methode to show it?
I already use the below code to show it, but its not work.
this.Cursor = new Cursor(Path.Combine(ImageDirectoryPath, "aero_busy.ani"));
Thanks in advance...
Krishnraj
modified on Thursday, November 13, 2008 3:22 AM
|
|
|
|
|
Hi,
I am working on Sign In and Sign Up functionality for my website.
Both options are on same page with two validation summary controls.
Sign In
I have 2 text boxes for Sign In [ User Name and Password ]
I have 1 Submit[Sign In] button which submits user name and password to server, its CausesValidation property is set to true for validation.
For each text box I am using 1 'required field validator' control.
For these text boxes I am using 1 Validation Summary Control.
Sign Up
I have 3 text boxes for Sign Up [ User Name, Password and Confirm Password]
I have 1 Submit button[Sign Up] which submits user name, password and confirm password to server, its CausesValidation property is set to true for validation.
For each text box I am using 1 'required field validator' control.
For these text boxes I am using another Validation Summary Control.
While working with mouse, both validations are working fine.
If I click on 'SignIn' button, first validation summary control's message box pops up.
If I click on 'SignUp' button, second validation summary control's message box pops up.
The problem is,
If I am a new user and trying to Sign Up. After providing required info, UserName, Password and Confirm Password... and ***** Press Enter ***** instead of Click 'Sign Up' button, it displays 'Sign In' validation Summary message box. Actually it should display 'Sign Up' Validation Summary message box.
Please help me to solve this problem.
Thanks.....
Ajit
|
|
|
|
|
The problem is that your sign in button has focus when you press on enter its event is fired.
So over come this problem, you have to register onfocus event of any textbox in signup panel. e.g text box for confirm password.
Then do the following in onFocus event of confirm Password text box.
textBoxConfirmPassword.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+btnSignUp.UniqueID+"').click();return false;}} else {return true}; ");
Ahsan Ullah
Senior Software Engineer
MCTS 2.0
|
|
|
|
|
Can someone please assist?
How can I pass a DataSet from the DataAccessLayer to the BusinessLogicLayer? Currently the DataSet gets populated successfully but as soon as the execution returns to the BusinessLogicLayer, the DataSet is null.
My DataAccessLayer Method looks something like this:
public object GetData(DataSet dsMyDataSet)
{
return dsMyDataSet;
}
My BusinessLogicLayer looks something like this:
public object GetData1()
{
datalayer = new datalayer();
datalayer.method();
}
Illegal Operation
|
|
|
|
|
Illegal Operation wrote: public object GetData(DataSet dsMyDataSet)
Why not returning the DataSet itself instead of object?
datalayer = new datalayer();
DataSet ds = datalayer.method();
I'd suggest to debug the code and findout why it is NULL. Also use strongly typed DTO's to transfer data between layers instead of DataSet/DataTable . Check this[^]
|
|
|
|
|
hi Illegal Operation
Why do you return an Object? You asked me an Unclear Question in my Article. Let me explain Briefly.
Illegal Operation :Wrote
My DataAccessLayer Method looks something like this:
public object GetData(DataSet dsMyDataSet)
{
return dsMyDataSet;
}
In your Getdata Function, you are Doing strange things, you return an Object and you asked us how to pass a dataset across DAL and BLL, First you have to change that object to a Dataset, and another thing in your Parameters, logically i dont know what you are trying to do. Your are accepting a Dataset as a Parameter and at the same time your want to return a dataset. When you getdata,it must be either void or search using something like string ,int etc not dataset. If you want to Pass the Dataset in this case you can change you function to look like this
public Dataset GetData()
{
return dsMyDataSet;
} ;
and lets come to your BLL
Illegal Operation :Wrote
My BusinessLogicLayer looks something like this:
public object GetData1()
{
datalayer = new datalayer();
datalayer.method();
}
Here again you return an Object, with what control are you going to bind the Object? Your Code
datalayer = new datalayer();
will not Compile, you did not create an Object of a Class. Your BLL Should look like this
;
public Dataset GetData1()
{
datalayer obj = new datalayer();
Dataset ds = new Dataset();
ds = obj.GetData();
return ds;
} ;
After you have this , you can bind it to any Control that you like.
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hey,
I have downloaded your source and saw that you instanciated a dataset in the PL before the method.
Anyway, your code has helped me solve my problem and for that I thank you!! I see that you are from South Africa?
I am also from South africa but I currently work as a software developer in Australia. For what company do you work? I worked for Business Connexion.
Thank you again for the article - it made a LOT of things clear...
Illegal Operation
|
|
|
|
|
Am From the Capital City "City of Tshwane" Previously Pretoria. Am working for the Municipality of Tshwane. Am Glad the Article Helped you, Did you Vote for it ? How is Australia ? I would like to have an Employer from outsite South Africa, but still South Africa is treating me well
Thanks
Vuyiswa Maseko,
Sorrow is Better than Laughter, it may Sadden your Face, but It sharpens your Understanding
VB.NET/SQL7/2000/2005
http://vuyiswamb.007ihost.com
http://Ecadre.007ihost.com
vuyiswam@tshwane.gov.za
|
|
|
|
|
Hello.
I am SourceGrid beginner.
The version uses 4.11.
The following tables were made.
|aaaaaaaaaaa|
|bbb|ccc|ddd|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
The first lines unite with columnspan.
Can able to be made it to scroll and how do by me without at that time though the line between ccc and ddd can be scrolled during bbb and ccc of the second line?
Moreover, RowHeader can be scrolled between line - numbers. Is there a method of not allowing this to be scrolled?
My best regards.
|
|
|
|
|
Hello everyone,
According to MSDN, we should "make exceptions serializable". I think it means we should implement the constructor which accepts SerializationInfo and StreamingContext as input parameter, correct?
If yes, could anyone show me how to implement it please?
http://msdn.microsoft.com/en-us/library/ms229064(VS.80).aspx
public class MyException : Exception
{
private int _errorCode;
private string _errorDescription;
public MyException (int errorCode, string errorMessage)
: base (errorMessage)
{
_errorCode = errorCode;
_errorDescription = errorMessage;
}
protected MyException (SerializationInfo info, StreamingContext context)
{
}
}
thanks in advance,
George
|
|
|
|
|
[Serializable]
public class MyException : Exception
{
private int _errorCode;
private string _errorDescription;
public MyException (int errorCode, string errorMessage)
: base (errorMessage)
{
_errorCode = errorCode;
_errorDescription = errorMessage;
}
protected Public MyException (SerializationInfo info, StreamingContext context)
: base(info,context)
{
this._errorCode = info.GetString("ErroCode");
}
} BTW, I have seen the same in MSDN forums too
|
|
|
|
|
Thanks Navaneeth,
Why you remove my string class member?
regards,
George
|
|
|
|
|
Base class Exception provides a member Message which can be used.
|
|
|
|
|
Thanks Navaneeth!
This constructor is called when an instance of type MyException is deserialized from a stream? So, the constructor is used in de-serialization process, not serialization process?
MyException (SerializationInfo info, StreamingContext context)
regards,
George
|
|
|
|
|
George_George wrote: This constructor is called when an instance of type MyException is deserialized from a stream?
I don't think so. Deserialization has to take place outside of the exception class and pass that SerializationInfo to this overload which will fill the necessary fields of this exception.
|
|
|
|
|
Thanks Navaneeth,
I am confused about -- "Deserialization has to take place outside of the exception class and pass that SerializationInfo to this overload which will fill the necessary fields of this exception." Especially confused about what means "take place outside of the exception class"? Could you show me some simple pseudo code please?
have a good weekend,
George
|
|
|
|
|
Im trying to send some GET and POST request to a website with the HttpWebRequest control.
The problem is that the server is giving me blank reponses when i try to do a post, and this is because the cookie i send doesnt have utma, utmz and utmc values, but i have no idea how to setup this variables, i tought they were gonna be set automatic like in the browser cause as far i know is for session tracking, but no
heres an example of the cookie values i dont know how to get/generate, sniffed from mozilla 3.0.3
__utma=56969722.1488837505.1226268589.1226445794.1226522343.8;__utmz=56969722.1226268589.1.1.utmccn= (direct)|utmcsr=(direct)|utmcmd=(none);__utmc=56969722;");
and heres my c# code
Code:
try
{
req = (HttpWebRequest)WebRequest.Create("http://www.domain.com/");
myWebHeaderCollection = req.Headers;
myWebHeaderCollection.Set("Accept-Language", "en-us;q=0.5,en;q=0.3");
myWebHeaderCollection.Set("Accept-Encoding", "gzip,deflate");
myWebHeaderCollection.Set("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
req.KeepAlive = true;
req.ServicePoint.Expect100Continue = false;
req.Referer = "";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)";
req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
req.Method = "GET";
req.CookieContainer = cookieContainer;
response = (HttpWebResponse)req.GetResponse();
sr = new StreamReader(response.GetResponseStream());
getOutput = sr.ReadToEnd();
sr.Close();
foreach (Cookie cook in response.Cookies)
{
cookieContainer.Add(cook);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
Any ideas how i could get this cookie?
|
|
|
|
|
what defferences between:
public void function1() and
public object function1()
Thanks
|
|
|
|
|
hunghero wrote: what defferences between:
public void function1() and
public object function1()
The first one doesn't return anything, the second one returns an object reference.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
when should we use a function or an object?
Thanks
|
|
|
|
|
first you must understand some types of method
1. a method that doesn't have any returns and parameters, in C# i.e : void methodname()
2. a method that pass parameters by value, this method doesn't change the parameters value after execute i.e : void methodname(object par1[, ...object parN])
3. a method that pass parameters by reference. This method will change the parameters value after execute i.e : void methodname(ref object par1[, ...ref object parN])
4. a method that return a value with or without parameters (either pass by value or by reference) object methodename([object par[, ref object var]]
in some programming language these method are divided into two that is procedure and function. A Procedure (Sub in VB) is a method that doesn't have a return value. A Function is a method that returned a value.
hunghero wrote: when should we use a function or an object?
when you needed
hope it helps
dhaim
ing ngarso sung tulodho, ing madyo mangun karso, tut wuri handayani. "Ki Hajar Dewantoro"
in the front line gave a lead, in the middle line build goodwill, in the behind give power support
|
|
|
|
|
Seriously, pickup a beginners book on C# and work through it. You're asking questions that would be covered in the first couple of chapters.
|
|
|
|
|
Dave Kreskowiak wrote: Seriously, pickup a beginners book on C# and work through it.
Ditto that.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|