Fenrir() 52 Newbie Poster

Click Here

Can't explain it any better than this.

Fenrir() 52 Newbie Poster

Do you have a KeyPress or KeyDown event linked to the textbox?

Fenrir() 52 Newbie Poster

So what's the problem? are you receiving errors? or is the code just not working in general?

Fenrir() 52 Newbie Poster

Have you tried anything yourself? This sounds like a typical homework assignment. Here are some links that could get you started on building a constructive question and actually post some code of your own.

Link
Link
Link
Link

Fenrir() 52 Newbie Poster

You can try something like this Article usually it would be better to host the database in a central location instead of user pc's. Or just use plain windows authentication. In your case you would need to display this screen on startup initially when the application first runs on a new client pc and then configure the connection and save the string.

Unfortunately this example is in VB but you can easily modify it and use it in your C# application as the namespaces would be the same.

Another example Link

Fenrir() 52 Newbie Poster

As depicted above. try inserting a breakpoint in your code on line 7

cmd.CommandText = "SELECT CAPITAL FROM TblProduct WHERE Description='" + descd.Text + "'and

Hover over the CommandText and look for a magnifying glass. Copy and paste the code into SQL and try executing it there and see if it runs without errors.

Fenrir() 52 Newbie Poster

Thanks seems to be working perfectly now.

Fenrir() 52 Newbie Poster

Is anyone else having problems viewing their Profile? It was working fine until about a day ago now everytime i click on my profile i just get a blank page. Tried reloading this multiple times even re-installed chrome

Fenrir() 52 Newbie Poster

Just to clarify. The reason you are receiving that message is due to the fact that after the SqlConnection was opened it was never closed. So your statement connection.Close(); never executed. By inserting a breakpoint and stepping your code you could have determined as to why.

Fenrir() 52 Newbie Poster

Do you mean that you want the first half to be centered on top and then the second part below it to be left alinged?

this is a very simple example you can test for yourself. If indeed i'm understanding you correctly

richTextBox1.AppendText("Header");
richTextBox1.SelectionAlignment = HorizontalAlignment.Center;
richTextBox1.AppendText(System.Environment.NewLine);
richTextBox1.AppendText("First Line");
richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
Fenrir() 52 Newbie Poster

I have a simple code for listing database elements in a listbox and I would like to add icon for each element

Just to explain this abit simpler seeing as you already have your database elements.

I have an ImageList with 3 images inside (Excel Document,PDF,Word)
I have 3 lines in want to add to my ListView (Document.xls,Document.pdf,Document.doc)

So when populating the ListView i want it do display as followed

Excel Document(Image) -> Document.xls
PDF(Image) -> Document.pdf
Word(Image) -> Document.doc

so i would write a simple switch statement to determine which item gets what icon depending on the extension when i create my ListViewItem "lvi"

switch (item.Substring(item.IndexOf(".")+1))
{
  case "xls":
    lvi.ImageIndex = 0; //The Index of the Excel Document Icon in my image list
  break;
  case "doc":
    lvi.ImageIndex = 1; // The Index of my Word Document Icon in my image list
  break;
  case "pdf":
    lvi.ImageIndex = 2; // The Index of my Pdf Document Icon in my image list
  break;
 }
Fenrir() 52 Newbie Poster

assuming the nodes in the XML are static you can just call an item from the list above by referencing the index. seeing as you know what item would be at what index string row1 = RetrievedValues[0].ToString(); I'm assuming this is what you're talking about when you say

C# List insert sql
Column1,Column2,Column3 ........

Fenrir() 52 Newbie Poster

Alot of examples here Click Here

Fenrir() 52 Newbie Poster

I don't see anything wrong with your code. as depicted in your code snippet above try inserting a breakpoint on lines 5,10 and hover over dropItems and dropItems2 it should display a count which should be 4 if the database returned more than 4 rows. Try pasting and running the query in SQL and see how many record are returned to ensure the data is correct.

Fenrir() 52 Newbie Poster

So where exactly are you have problems? are you getting exception? Or is the data not displaying in your file? Are you limited to a certain type of file?

Sorry for all the question but it makes it alot easier to help you.

Fenrir() 52 Newbie Poster

Is there some problem with the code? Or is it merely for imformative purposes?

Fenrir() 52 Newbie Poster

Try this. (c as CheckedListBox).CheckedItems.Count

Fenrir() 52 Newbie Poster

Can't quite remember where i found this but it works like a charm.

Add the following method in your application

public IEnumerable<T> FindControls<T>(Control control) where T : Control
{
  var controls = control.Controls.Cast<Control>();

  return controls.SelectMany(ctrl => FindControls<T>(ctrl))
                                     .Concat(controls)
                                     .Where(c => c.GetType() == typeof(T)).Cast<T>();
}

Then you can call it as followed.

var t = FindControls<CheckedListBox>(this);

foreach(Control c in t)
{
  MessageBox.Show(c.Name);
}

This will for example bring back all the checklistboxes on the control you called the method with. Above the form is being passed in. this

ddanbe commented: Nice! +15
Fenrir() 52 Newbie Poster

Could you please post your code that populates the grid. Are you manually defining the columns on the grid? or are they auto generated by the item source. If they are manual you need to remove the auto size property and set it to *

Fenrir() 52 Newbie Poster

After adding a datagrid to the dockpanel add the following in your XAML for your datagrid.

Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualHeight}"

This will force your datagrid to maintain the host window's height.

The width seems to be handeled correctly by the dock panel.

your Main component on the screen should not be the default grid change this to a dockpanel and set the property LastChildFill to true and drop your datagrid onto this dockpanel.

<DockPanel LastChildFill="True">

Are you Auto Generating the Columns from the ItemSource?

Fenrir() 52 Newbie Poster

Try adding it to a dock Panel Click Here

Fenrir() 52 Newbie Poster

You should be able to create a user control for this in the WPF side and then use an element host in your winforms application. Here is a nice link describing it Click Here. You'll probably need to take the plunge and sharpen up on your WPF though. even if it's just a little bit

Fenrir() 52 Newbie Poster

There might be a better way but i'm lazy so i loaded the image into the picturebox it ads the size mode and then i save and load the image from a temporary directory. Click Here this ensures that the sizemode is applied to the image

--Edit
this might be a better way actually Click Here you can resize the image on the fly in your base64 method and then save it to the stream

dhatsah commented: Thanks the second method was perfect. +0
Fenrir() 52 Newbie Poster

So you're saying that on table 1 you have 3 column values in one column? and you want to split it and add it to columns 1,2 and 3 in table 2? Just want to be clear

Fenrir() 52 Newbie Poster

You would be able to do this with a listview yes. But it will be far from easy Have you tried anything on your own? start small instead of thinking of the entire application.

Click Here How to create a listview with columns

Click Here here are some examples on looping a listview which you will need to update values from the textbox.

this should help you get started. Once you created something we can help you further

Fenrir() 52 Newbie Poster

Create a new public class and declare a static connection string public static string SqlConnection = Your .sdf connection string or just declare an actaul SqlCeConnection instead of a string. Just remember to add your using statements to the class. you can then call this anywhere in your application by typing the ClassName.SqlConnection.

Fenrir() 52 Newbie Poster

So you're not using DateTimePickers for the dates? the problem is that when a textbox has no value the value is actually a blank string " " and not Null. So you need to do a check. IF (string.IsNullOrEmpty(StartDate)){} and then assign it a default value like 1900-01-01 00:00:00.000 and then do the same for end date you can you DateTime.Now for that

Fenrir() 52 Newbie Poster

if (comboBox2.Items[comboBox2.SelectedIndex].ToString() == "1") Do you mean this line? Could you please paste the exception you are getting?

Fenrir() 52 Newbie Poster

You mean If (Textbox2.Text == "") ? you should be able to add that in the text changed event

Fenrir() 52 Newbie Poster

Try adding a breakpoint on row 10 and checking the value of your RowFilter by hovering on it a small magnifying glass should appear. Click it and paste the text into SQL server and add the SELECT * FROM TableName WHERE and check the results.

Alternatively you can try the following line of code which reads much simpler.

(dataGridView1.DataSource as DataTable).DefaultView.RowFilter = string.Format("CashAccRef LIKE '%{0}%' OR CashName LIKE '%{1}%'", textBox2.Text,textbox2.Text);

When stepping your code make sure that none of the datasets you're using still have a previous row filter applied when running the application for all IF scenarios.

Fenrir() 52 Newbie Poster

You can use this Click Here

Fenrir() 52 Newbie Poster

I've had this in the past and i felt pretty stupid but there wasn't enough space to actually create the file which will probably not be the case seeing as the file in question is so small (But still). Another issue i've come accross was permissions. Try uploading the file without code via windows explorer or another 3rd party application and see if that works.

Fenrir() 52 Newbie Poster

Once you have the value from the database you should have no problem concatenating the prefix. Or are we missing something?

Click Here

Here's a good example that might help you. Instead you will type

Textbox1.Text = "EMP"+SqlCommand.ExecuteScalar();

you will obviously have to do some conversions and exception handling but i think you'll get the idea.

Fenrir() 52 Newbie Poster

I would suggest you get the max emp ID from the database first and then increment it by whatever you need SELECT MAX(Emp_Id)+1 FROM Table

Fenrir() 52 Newbie Poster

For this type of application it would probably better suit you to use something like an XML file or database. The problem is passing data from one form to another. You're initiating the new(StudentList) in both forms which means that they would hold different data and no way of knowing what the other one contains. So a simple way would be Declaring your student list static in your main form public static List<Student> Students; And then when calling the add form declare it as follows List<Student> StudentListFromFirstForm = Form1.Students;

Fenrir() 52 Newbie Poster

Click Here Have a look here

Fenrir() 52 Newbie Poster

A very quick google led me to this Click Here that should help you getting started on writing your own code for accomplishing this.

Fenrir() 52 Newbie Poster

Can you post the exact error you are receiving

Fenrir() 52 Newbie Poster

Click Here

This article should help you understand the problem.

with the current collation settings on your database the above query should return llo ??????

Fenrir() 52 Newbie Poster
else
{
  MessageBox.Show("Invalid user name or password. Please try with another user name or password", "Task", MessageBoxButtons.OK, MessageBoxIcon.Warning);
  txtUsername.Focus();
}

A simple solution would be adding a field on your user table namely "LoginAttempts" INT

When they attempt to login with the incorrect password for the given username you simply update the field for that user and check the value in your code. if LoginAttempts == 3 then Display another message saying you have exceeded the maximum number of logins for DateTime.Now()

it think you can take it from there.

Fenrir() 52 Newbie Poster

What exactly do you have in your checklistbox? If you want an Insert Statement to run for each item in your checklistbox then you have to assign your parameters and execute inside your for (int a = 0; a < CheckBoxList1.Items.Count - 1; a++)

Fenrir() 52 Newbie Poster

Can you please paste the exact error you are receiving

Fenrir() 52 Newbie Poster
decimal Summe = 0;     // <-- outside loop
for (int y = 1; y < nofrows; y++)
{
  line = sReader.ReadLine();
  tileNo = line.Split(',');
  string unparsedDate = tileNo[0];
  DateTime datum = Convert.ToDateTime(unparsedDate.Substring(unparsedDate.IndexOf("(") + 1, (unparsedDate.IndexOf(")") - unparsedDate.IndexOf("(") - 1)).Replace(".", "-"));
  if (datum > DateStart && datum < DateEnd)
  {
    Summe = Summe+Convert.ToDecimal(tileNo[tileNo.Length - 1]);
  }
}

This will get the total for all summe's in the file for the dateStart and DateEnd provided.

Fenrir() 52 Newbie Poster

The variable datum is only assigned inside your try{} so that's where you need to do your comparisons

Fenrir() 52 Newbie Poster

Glad we could be of assistance.

Fenrir() 52 Newbie Poster

Sorry i was assuming you were using MS SQL here is the C# version

string test = "41521.880937(04.09.13 21:08:33)";
DateTime date = Convert.ToDateTime(test.Substring(test.IndexOf("(")+1, (test.IndexOf(")") - test.IndexOf("(")-1)).Replace(".","-"));

output : 4/9/2013 9:08:33 PM

Fenrir() 52 Newbie Poster

So you're looking for something like this?

DECLARE @Val VARCHAR(100) = '41521.880937(04.09.13 21:08:33)'
SELECT CAST(REPLACE(SUBSTRING(@Val,CHARINDEX('(',@Val,0)+1,(CHARINDEX(')',@Val,0)-CHARINDEX('(',@Val,0)-1)),'.','-') AS DATETIME) AS Date

Wrote this very quickly so feel free to play around with it this code assumes the date will be in the above mentioned format.

Fenrir() 52 Newbie Poster

Could you please post your question on a new thread seeing as you've marked this one as solved.

Fenrir() 52 Newbie Poster

When are you reading the data from the files? when a user inputs data you want to go get values from the file and compare?

Fenrir() 52 Newbie Poster

If this is the error you are still getting 'Incorrect syntax near '@Numberpassengers'.' then remember INSERT INTO(Columns) VALUES (Values) Remember your Parenthesis ( ) ( ) you are missing the last one for VALUES you have VALUES (... add an ")"