Click here to Skip to main content
15,899,026 members
Home / Discussions / C#
   

C#

 
AnswerRe: Attempt to write in a readonly database ERROR Pin
Pete O'Hanlon21-Jul-15 8:25
mvePete O'Hanlon21-Jul-15 8:25 
QuestionSystem.DirectoryServices.ActiveDirectory Missing Pin
Toni7821-Jul-15 4:31
Toni7821-Jul-15 4:31 
AnswerRe: System.DirectoryServices.ActiveDirectory Missing Pin
Dave Kreskowiak21-Jul-15 5:10
mveDave Kreskowiak21-Jul-15 5:10 
GeneralRe: System.DirectoryServices.ActiveDirectory Missing Pin
Toni7821-Jul-15 23:47
Toni7821-Jul-15 23:47 
GeneralRe: System.DirectoryServices.ActiveDirectory Missing Pin
Ferd Really21-Jul-15 5:21
Ferd Really21-Jul-15 5:21 
GeneralRe: System.DirectoryServices.ActiveDirectory Missing Pin
Toni7821-Jul-15 23:49
Toni7821-Jul-15 23:49 
AnswerRe: System.DirectoryServices.ActiveDirectory Missing Pin
PIEBALDconsult21-Jul-15 9:52
mvePIEBALDconsult21-Jul-15 9:52 
GeneralRe: System.DirectoryServices.ActiveDirectory Missing Pin
Toni7821-Jul-15 23:48
Toni7821-Jul-15 23:48 
Questionvisual studio 2015 local database help Pin
jamesmc153520-Jul-15 21:38
jamesmc153520-Jul-15 21:38 
AnswerRe: visual studio 2015 local database help Pin
Eddy Vluggen21-Jul-15 0:26
professionalEddy Vluggen21-Jul-15 0:26 
GeneralRe: visual studio 2015 local database help Pin
jamesmc153521-Jul-15 0:29
jamesmc153521-Jul-15 0:29 
GeneralRe: visual studio 2015 local database help Pin
Eddy Vluggen21-Jul-15 1:15
professionalEddy Vluggen21-Jul-15 1:15 
GeneralRe: visual studio 2015 local database help Pin
jamesmc153521-Jul-15 1:17
jamesmc153521-Jul-15 1:17 
GeneralRe: visual studio 2015 local database help Pin
Eddy Vluggen21-Jul-15 8:10
professionalEddy Vluggen21-Jul-15 8:10 
AnswerRe: visual studio 2015 local database help Pin
Richard MacCutchan21-Jul-15 3:35
mveRichard MacCutchan21-Jul-15 3:35 
QuestionAssigning Tuple.Create to a Func ? ... an interesting code fragment Pin
BillWoodruff20-Jul-15 8:51
professionalBillWoodruff20-Jul-15 8:51 
AnswerRe: Assigning Tuple.Create to a Func ? ... an interesting code fragment Pin
Sascha Lefèvre23-Jul-15 12:57
professionalSascha Lefèvre23-Jul-15 12:57 
GeneralRe: Assigning Tuple.Create to a Func ? ... an interesting code fragment Pin
BillWoodruff23-Jul-15 21:52
professionalBillWoodruff23-Jul-15 21:52 
Questionimplement duplex wcf service in iis Pin
tehran135720-Jul-15 2:54
tehran135720-Jul-15 2:54 
AnswerRe: implement duplex wcf service in iis Pin
Pete O'Hanlon20-Jul-15 3:16
mvePete O'Hanlon20-Jul-15 3:16 
AnswerRe: implement duplex wcf service in iis Pin
Eddy Vluggen20-Jul-15 7:47
professionalEddy Vluggen20-Jul-15 7:47 
QuestionDeploy POS.NET files Pin
Jassim Rahma20-Jul-15 2:42
Jassim Rahma20-Jul-15 2:42 
AnswerRe: Deploy POS.NET files Pin
ZurdoDev20-Jul-15 8:47
professionalZurdoDev20-Jul-15 8:47 
QuestionCreating a SELECT Query Based on Textbox Data Pin
John L. DeVito19-Jul-15 4:59
professionalJohn L. DeVito19-Jul-15 4:59 
I'm building a simple windows form app which stores all of my DVD's (pet project, just for learning; I'm sure there are plenty already out there). I'm able to add items into the database (azure SQL Server) perfectly, even leaving some or most textboxes blank (the title column is setup as NOT NULL in my table) but I can't get it to retrieve any data.

Here is my OnClick method:

C#
private void searchButton_Click(object sender, EventArgs e)
{
	string qString = @"SELECT Title, Director, Genre, ReleaseYear, Length, NumberofDisks, Description FROM Base WHERE Title = '" + titleTextbox.Text + "' AND Director = '" + directorTextbox.Text + "' AND Genre = '" + genreCombobox.GetItemText(genreCombobox.SelectedItem) + "' AND ReleaseYear = '" + yearCombobox.GetItemText(yearCombobox.SelectedItem) + "' AND Length = '" + lengthTextbox.Text + "' AND NumberOfDisks = '" + numberOfDisksTextbox.Text + "' AND Description = '" + descriptionTextbox.Text + "';";
	
    string cString = @"Server=MyAzureServer,MyPortNumber;Database=MyDatabase;User ID=me@MyAzureServer;Password=MyPassword;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";

	DataTable dTable = new DataTable();

	SqlConnection sConnection = new SqlConnection(cString);

	sConnection.Open();

	using(SqlCommand sCommand = new SqlCommand(qString, sConnection))
        {
        	try
		{
			SqlDataReader sReader = sCommand.ExecuteReader();
			dTable.Load(sReader);
		}
		catch(SqlException sEx)
		{
			MessageBox.Show(sEx.Message);
		}

		resultsDataGridView.DataSource = dTable;
	}

		sConnection.Close();
}


and here is my table:

SQL
CREATE TABLE [dbo].[Base]
(
	[MediaID] [int] IDENTITY(1,1) PRIMARY KEY,
	[Title] [nvarchar](50) NOT NULL,
	[Director] [nvarchar](50) NULL,
	[Genre] [nvarchar](50) NULL,
	[ReleaseYear] [date] NULL,
	[Length] [time] NULL,
	[NumberOfDisks] [int] NULL,
	[Description] [nvarchar](200) NULL
)


I absolutely realize this is open to SQL injection. My plan is to just 'get it working' and then I will go back over it and and change to parameterized queries (I have to read up on how to use them). The program compiles and runs fine. When I click the search button with all or any of the textboxes filled, it returns no results in the datagridview. The white grid shows up but it is empty. I can query the database directly and get the results I'm looking for, but not programatically. Do I need to build the query using logic? Since almost all of my columns accept null (except Title) I'm assuming leaving a field blank wouldn't be a problem, but even if I enter data into all of the available textboxes(exact matches including case just to be certain) I get no results. Am I missing something small and stupid?

Can anyone give me any help or hints? Please no laughing at my code or making fun of me Laugh | :laugh:
Thanks,
John

"Only a fool learns from his own mistakes, but a wise man learns from the mistakes of others." -Unknown

GeneralRe: Creating a SELECT Query Based on Textbox Data Pin
PIEBALDconsult19-Jul-15 5:06
mvePIEBALDconsult19-Jul-15 5:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.