|
hi can you help me about my problem regarding this C# program. I try to update but this error always show. what is the meaning of Syntax error in UPDATE statement: ? thank you so much. your reply will highly appreciated.
|
|
|
|
|
Sounds like a database question, not a C# question.
What error?
|
|
|
|
|
It means that your UPDATE statement is not correct in some way, but unless you show us the actual details we cannot guess what the problem may be.
Use the best guess
|
|
|
|
|
As Richard says, without your actual code and the UPDATE command istelf, we can't tell you exactly what the problem is.
An SQL update statement is similar to this:
UPDATE <table_name> SET <field>=<new value>,<field... WHERE <field>=<value> So an example would be:
UPDATE myTable SET UserName='kruczynski123' WHERE UserID=9738136 So, check you have each section of it, or very similar, and check you have quotes where you need them. If you are using C# (and I assume you are) then try using Parametrized queries - they may help you (and you should use them anyway to prevent an SQL Injection attack accidentally of deliberately destroying your database). This may help:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand com = new SqlCommand("UPDATE myTable SET myColumn1=@C1, myColumn2=@C2 WHERE Id=@ID", con))
{
com.Parameters.AddWithValue("@ID", id);
com.Parameters.AddWithValue("@C1", myValueForColumn1);
com.Parameters.AddWithValue("@C2", myValueForColumn2);
com.ExecuteNonQuery();
}
}
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
Or it could be
UPDATE <table_name> SET <field>=<new value>,<field... FROM ...
|
|
|
|
|
Error in update query? Check if the parameters you are passing into the query are all correct and in the right format.
|
|
|
|
|
How to connect two forms in a C# project in a way that in a button click event to the other form from form1, the form1 must be closed the moment the form2 is diaplayed on the screen
|
|
|
|
|
coolvibhu wrote: connect two forms
Nothing in here suggests that you need to "connect" the forms in anyway. All you need is
Form2 frm = new Form2();
frm.Show();
this.Hide();
Or close form 1 but that will probably also close your application. Kind of hard to tell since you did not post any code for what you have tried.
|
|
|
|
|
That depends on how you want to do it.
If Form1 is opening Form2, then it's pretty simple:
Form2 f2 = new Form2();
Hide();
f2.ShowDialog(): Then either
Show(); Or
Close(); Depending on if you want Form1 redisplayed or not. Do note that if Form1 is your startup form, then closing it will end the application - even if you have displayed a Form2 from Form1, it will be closed as well.
If you have a third form involved which opens Form1, then Create an event in Form1 which it's parent handles and which causes the parent to open Form2. Once Form1 has signalled the event, it can close itself.
The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)
|
|
|
|
|
i create a winform program that load the data from ms access database to my listbox. when i click my item which i want to update on database and datasource on my listbox and click the update button, the item just wont update for the first time clicked but the second does, so everytime i need to modify my data i need to choose my item and click the update button two times. that's is crazy lol..
private void buttonUpdate_Click(object sender, EventArgs e)
{
OleDbDataAdapter cmd = new OleDbDataAdapter();
cmd.UpdateCommand = new OleDbCommand("UPDATE Item SET ITEM = @ITEM, ITEM_DESC = @ITEM_DESC WHERE ID = @ID",GetConnection());
cmd.UpdateCommand.Parameters.AddWithValue("@ITEM", textBoxITEM.Text);
cmd.UpdateCommand.Parameters.AddWithValue("@ITEM_DESC", textBoxITEMDESC.Text);
cmd.UpdateCommand.Parameters.AddWithValue("@ID", Convert.ToInt32(textBoxID.Text));
cmd.UpdateCommand.ExecuteNonQuery();
_productlist.Clear();
listBox1.DataSource = null;
listBox1.Items.Clear();
Fill();
listBox1.Update();
}
basic thing that happen:
1. load data to listbox with databind to textbox
2. click item on my listbox and modify data from textbox
3. click the update button to update database and datasource
4. datasource not update for the first time but database does update
5. repeat no.2
6. repeat no.3
7. datasource updated
what i want:
1. load data to listbox with databind to textbox
2. click item on my listbox and modify data from textbox
3. click the update button to update database and datasource
4. datasource and database updated
how do i fix this bug on my application?? please let me know if i need to be more clear..
|
|
|
|
|
you are not adding any items to the listview neither assigning a datasource.
What does the 'Fill();' do?
Think! Don't write a line of code unless you absolutely need to.
|
|
|
|
|
this is what the fill do..anyway just to let ya know that i also call this on form_load
private void Fill()
{
string strSQL = "SELECT * FROM Item ORDER BY ITEM";
OleDbDataAdapter myCmd = new OleDbDataAdapter(strSQL, GetConnection());
DataSet dtSet = new DataSet();
myCmd.Fill(dtSet, "Item");
DataTable dTable = dtSet.Tables[0];
foreach (DataRow dtRow in dTable.Rows)
{
_productlist.Add(new PRODUCTLIST() { ID = dtRow["ID"].ToString(), ITEM = dtRow["ITEM"].ToString(), ITEM_DESC = dtRow["ITEM_DESC"].ToString() });
}
listBox1.DisplayMember = "ITEM";
listBox1.DataSource = _productlist;
listBox1.ValueMember = "ID";
GetConnection().Close();
}
|
|
|
|
|
Hi,
What is the _productList?
Why are you adding dtSet to _productList then to ListBox?
ListBox, only takes one colum of data, list box will not data bind to a dataset.
you need ListView control, and
listView1.DataSource = dtSet;
Should do the trick for you.
Regards
Jegan
Think! Don't write a line of code unless you absolutely need to.
modified 19-Mar-13 12:19pm.
|
|
|
|
|
Hello everyone,
I need to export gridview data in pdf where suppose i have 50 records...so first 10 records should come in 1st page...next 11 to 20 in next page...so on..
here is my code:
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
StringReader sr = new StringReader(sw.ToString());
Document document = new Document(PageSize.A4, 0, 0, 50, 50);
HTMLWorker htmlparser = new HTMLWorker(document);
PdfWriter writer = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
htmlparser.Parse(sr);
iTextSharp.text.Table datatable = new iTextSharp.text.Table(columns, tableRows);
datatable.BorderWidth = 1;
datatable.BorderColor = new Color(0, 0, 255);
datatable.Cellpadding = 3;
datatable.Cellspacing = 3;
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
Cell c2 = new Cell(this.GridView1.Columns[0].HeaderText);
datatable.AddCell(c2);
datatable.AddCell(this.GridView1.Columns[1].HeaderText);
datatable.AddCell(this.GridView1.Columns[2].HeaderText);
datatable.AddCell(this.GridView1.Columns[3].HeaderText);
for (int rowCounter = 0; rowCounter < rows; rowCounter++)
{
for (int columnCounter = 0; columnCounter < columns; columnCounter++)
{
string strValue = GridView1.Rows[rowCounter].Cells[1].Text;
datatable.AddCell(strValue);
}
if (rowCounter > 0)
{
document.Add(datatable);
document.NewPage();
}
}
document.Close();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment; filename=GridViewwithPagebreak.pdf");
Response.Write(document);
Response.End();
anyone have idea...how to do that?? what changes i have to make??
|
|
|
|
|
You'll need a library that understands the PDF format; writing it as text and setting the content-type will not be sufficient. Search CodeProject for some articles on creating PDF files.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
i have imported library for pdf creation
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html;
using iTextSharp.text.html.simpleparser;
using System.Text;
i am also getting gridview records in pdf.
my problem is i need 10 rows per page. So next 10 record(11 to 20) should be displayed with header name in next page of pdf.
|
|
|
|
|
AlexRusso wrote: my problem is i need 10 rows per page. So next 10 record(11 to 20) should be displayed with header name in next page of pdf.
Fetch all records, and write them in groups of 10 to the page. You might get better help if you include the code that's causing the problem.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello friends. my question is very short. I only used one filesystemwather and nothing else. And used its created method. But when i send a file into the folder, it throws this error:"Exception has been thrown by the target of an invocation." on this line: Application.Run(new Form1()); Do you know why?
|
|
|
|
|
the exception is not really on that line. its somewhere inside the Form1 class. can you post the complete exception stack ? try to debug your application step by step you can able to track down this error.
|
|
|
|
|
Yes you are right. This is what i found in intellitrace:
Exception:Thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process." (System.IO.IOException)
A System.IO.IOException was thrown: "The process cannot access the file 'd:\deneme\OCTOPUSxml-66907571 - Copy.xml' because it is being used by another process."
Exception:Thrown: "Exception has been thrown by the target of an invocation." (System.Reflection.TargetInvocationException)
A System.Reflection.TargetInvocationException was thrown: "Exception has been thrown by the target of an invocation."
In created method of filewatcher, i have these codes:
XmlDocument xdc = new XmlDocument();
xdc.Load(e.FullPath);
Somehow, grasping the file by filewatcher and loading by xmldocument occur almost at the same time. To be sure i changed the code as :
XmlDocument xdc = new XmlDocument();
System.Threading.Thread.Sleep(1000);
xdc.Load(e.FullPath);
System.Threading.Thread.Sleep(1000);
I know this is not professional but now it is working
|
|
|
|
|
Sleep is not the right choice. can you paste the code on how you initialize the file watcher instance. I guess its FileCreated event you are watching,while other application create and manage the file you are trying to load this in your form.
|
|
|
|
|
FileSystemWatcher doesn't "grab" files. It doesn't touch them at all.
The file is either being held open by your process using some other method, or some other process has the file open and locked, like something that outputs the file?? Or some editor??
|
|
|
|
|
leone wrote: Do you know why?
..because of an unhandled error in a constructor, probably the one from Form1 . Paste your code and we'll have a look.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
In a C# 2008 desktop application, the application is having a problem
determining if a folder exists on a network drive.
I am using code that looks like the following:
using System.IO
if (!File.Exists(myfile))
Console.WriteLine("The file does not exists.");
The value for the directory comes from a column in the database that
looks like the following:
//servername/mdain/myfile.xls".
Thus can you tell me what I can do so this application is aware that the file does exist on the network drive?
|
|
|
|
|
The first thing I see is that your sample path you provided is wrong. You are using the wrong slash in the path, it should be "\\servername\mdain\myfile.xls". The second thing I would check is if the computer you are running the application on has permissions to access the network drive, since that would return false regardless of the file existing.
|
|
|
|