I'm having problem with a school assignment. I'm almost done with my program but I have one problem that I can't solve. The problem is with one of my SQL query's that are supposed to show players with different scores. When running my program I get the following error: Syntax error near expression..
My code:
The picture shows the GUI and how it is supposed to work. By entering 0,3 and 0,4 in the textboxes should filter out the player "Jack Blue".Code:// Filters players. WORKS private void button1_Click(object sender, EventArgs e) { view.RowFilter = "LastName like '%" + textBox1.Text + "%'"; if (textBox1.Text == "") view.RowFilter = string.Empty; } // Connection to the database. WORKS private void Form1_Load(object sender, EventArgs e) { DataTable datatable = new DataTable(); SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Mattias\Dropbox\C#\Databases\Baseball.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"); connection.Open(); datatable.Load(new SqlCommand("select * from players", connection).ExecuteReader()); dataGridView1.DataSource = view = datatable.DefaultView; connection.Close(); } // The following doesn't work private void button2_Click(object sender, EventArgs e) { decimal minimum = Convert.ToDecimal(textBox2.Text); decimal maximum = Convert.ToDecimal(textBox3.Text); // This is where the debugger throws the exception view.RowFilter = String.Format("BattingAverage >= {0} AND BattingAverage <= {1}", minimum, maximum); if (textBox2.Text == "") view.RowFilter = string.Empty; if (textBox3.Text == "") view.RowFilter = string.Empty; }
Can someone please help me and explain what I can do to solve this problem?
// Moff :-)


Reply With Quote
Bookmarks