Click here to Skip to main content
15,915,093 members
Home / Discussions / Database
   

Database

 
AnswerRe: How can I... Pin
Roger Wright7-Jan-05 14:01
professionalRoger Wright7-Jan-05 14:01 
GeneralMy problem... Pin
KORCARI7-Jan-05 13:30
KORCARI7-Jan-05 13:30 
GeneralRe: My problem... Pin
Colin Angus Mackay8-Jan-05 6:59
Colin Angus Mackay8-Jan-05 6:59 
GeneralSQL Statement Problem Pin
Anonymous7-Jan-05 5:24
Anonymous7-Jan-05 5:24 
GeneralRe: SQL Statement Problem Pin
Mike Ellison7-Jan-05 5:33
Mike Ellison7-Jan-05 5:33 
GeneralRe: SQL Statement Problem Pin
Anonymous7-Jan-05 8:22
Anonymous7-Jan-05 8:22 
GeneralRe: SQL Statement Problem Pin
Mike Ellison7-Jan-05 9:14
Mike Ellison7-Jan-05 9:14 
GeneralRe: SQL Statement Problem Pin
Anonymous7-Jan-05 10:23
Anonymous7-Jan-05 10:23 
Thanks Mike for your help, you have been a great help.
This is my first experience (posting question to online forums) & it has very good.

I agree with you about using parameter value instead of using as a string literal into the sql statement.

I'm using SQL Server & VB.NET for this project.

Okay now when I used the parameter code I got a different error which is following:

Code ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Private Sub btnSrch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSrch.Click
Dim objConnection As SqlConnection
Dim objCommand As SqlCommand
Dim objAdapter As SqlDataAdapter
Dim objDataReader As SqlDataReader
Dim objDataSet As DataSet
Dim strSearch As String
Dim StrSQLQuery As String

'Get Search
strSearch = txtSrch.Text

'If there's nothing to search for then don't search
' o/w build our SQL Query execute it.
If Len(Trim(strSearch)) > 0 Then
'Set up our connection.
objConnection = New SqlConnection("server=(local);Integrated Security=SSPI;database=Equipment Log")

'-- setup the select command
StrSQLQuery = "Select * From Equip Where txtSrch = @param1 AND ddlSrchby = @param2"

'--create the SqlCommand object (a connection would need to be set up too)
Dim cmd As SqlCommand = New SqlCommand(StrSQLQuery)

'--add parameter values retrieved from the submitted form
cmd.Parameters.Add("@param1", txtSrch.Text)
cmd.Parameters.Add("@param2", ddlSrchby.SelectedItem.Value)

'--execute the query and fill a dataset with the results
Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Dim ds As DataSet = New DataSet
da.Fill(ds)

'Create new command object passing it our SQL Query
'and telling it which connection to use.
objCommand = New SqlCommand(strSearch, objConnection)
objConnection.Open()

Else
txtSrch.Text = "Enter Serach Here"
End If

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Here is the error I got

Fill: SelectCommand.Connection property has not been initialized.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Fill: SelectCommand.Connection property has not been initialized.

Source Error:

Line 175: Dim da As SqlDataAdapter = New SqlDataAdapter(cmd)
Line 176: Dim ds As DataSet = New DataSet
Line 177: da.Fill(ds)

Thanks and have a happy new year to you too.
GeneralRe: SQL Statement Problem Pin
Colin Angus Mackay7-Jan-05 10:39
Colin Angus Mackay7-Jan-05 10:39 
GeneralRe: SQL Statement Problem Pin
Anonymous7-Jan-05 11:07
Anonymous7-Jan-05 11:07 
GeneralRe: SQL Statement Problem Pin
Colin Angus Mackay7-Jan-05 11:13
Colin Angus Mackay7-Jan-05 11:13 
GeneralRe: SQL Statement Problem Pin
Colin Angus Mackay7-Jan-05 10:42
Colin Angus Mackay7-Jan-05 10:42 
GeneralRe: SQL Statement Problem Pin
David Salter7-Jan-05 5:36
David Salter7-Jan-05 5:36 
GeneralRe: SQL Statement Problem Pin
Anonymous7-Jan-05 6:46
Anonymous7-Jan-05 6:46 
GeneralRe: SQL Statement Problem Pin
tecnovate_vivek8-Jan-05 1:37
tecnovate_vivek8-Jan-05 1:37 
Generalinsert record into mysql table Pin
kd83417-Jan-05 3:25
kd83417-Jan-05 3:25 
GeneralRe: insert record into mysql table Pin
David Salter7-Jan-05 5:42
David Salter7-Jan-05 5:42 
QuestionOnly last 50 rows??? Pin
Anonymous7-Jan-05 2:43
Anonymous7-Jan-05 2:43 
AnswerRe: Only last 50 rows??? Pin
Ritesh12347-Jan-05 3:09
Ritesh12347-Jan-05 3:09 
GeneralRe: putting strings into sqlcommand Pin
Colin Angus Mackay6-Jan-05 22:26
Colin Angus Mackay6-Jan-05 22:26 
GeneralExcel text field not taking big CString using VC++ Pin
Anshul Mehra6-Jan-05 20:20
professionalAnshul Mehra6-Jan-05 20:20 
Generalputting strings into sqlcommand Pin
sianatia6-Jan-05 18:34
sianatia6-Jan-05 18:34 
GeneralAngry DBA Pin
Anonymous6-Jan-05 14:24
Anonymous6-Jan-05 14:24 
GeneralODP.NET : How to access function with VARCHAR2 as ReturnValue Pin
arnab19745-Jan-05 16:49
arnab19745-Jan-05 16:49 
QuestionHow to use insert command in Access database? Pin
DuyNguyen5-Jan-05 7:43
DuyNguyen5-Jan-05 7:43 

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.