erikos Posted August 8, 2006 Share Posted August 8, 2006 Hi everyone...First of all I am using visual Basic 2005.I have created an sql database which contains 2 tables and some queries.What i want to do is to search the first table with multiple fields in every search.My table consist of :-SN (serial number)-GeneralDescription-Type-StoredSn (stored in serial number)-efile (electronic file)-StatusI have created a form which contains these fields and i want to search for a serial number dependig the fields i have written something on. Maybe i should use the AND, OR statements but how i will avoid the NULL fieldsI really need your help...thxerrikos Link to comment Share on other sites More sharing options...
dcole.ath.cx Posted August 8, 2006 Share Posted August 8, 2006 use an if statemment to check if the field is null. Then don't take that field into account...I would get each thing at a time, like get everything that matches field one... unless it's empty, then get all the data. Then take the remaining data and only keep what the 2nd field has and though the rest away, unless the field is null... then keep all the data from before you started this one. Continue doing that until your done with all the fieldsso again it will be like: get all data: if not blank remove data that doesn't match: if not blank remove data that doesn't match: if not blank remove data that doesn't match: if not blank remove data that doesn't match: anwser(s) Link to comment Share on other sites More sharing options...
erikos Posted August 9, 2006 Author Share Posted August 9, 2006 Thank you very much....It helped me a lotSomething else now...I am creating a new temporary table like this : Public temptable As New cisDataSet.ItemDataTable i fill it with data and i want to use sql statements inside my codei do like this Dim sqlmsg As Stringsqlmsg = "SELECT SN, DateEntry, DateUpdate, GeneralDescription, Type, StoredSn, eFile, Status FROM item WHERE (GeneralDescription LIKE '%something%')"temptable.Select(sqlmsg) and when i run my application an error occurs Syntax error : Missing Operrand after 'SN' operator.For sure i am using in wrong way the sql statements in my codeCan anyone tell me the correct way...Thx in advanceerrikos Link to comment Share on other sites More sharing options...
erikos Posted August 10, 2006 Author Share Posted August 10, 2006 Hello againtoday i try to use the sqlclient in my vb code Dim sqlmsg As String sqlmsg = "SELECT * FROM Item Where eFile Like '%" & text & "%'" '''text is given by user Dim connectionstring As String = cisproject.My.Settings.cisdatabaseConnectionString Dim i As Integer Using connection As New SqlClient.SqlConnection(connectionstring) connection.Open() Dim command As New SqlClient.SqlCommand(sqlmsg, connection) Dim reader As SqlClient.SqlDataReader = command.ExecuteReader() While reader.Read() For i = 0 To 7 ''''i have 8 columns in the table temptable.NewRow.Item(i) = reader(i) Next End While End Using when i run this it fills the temptable with the whole table in my databasecan you see the problem? Or can you suggest me a better solution to this?thank you in advanceerrikos Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now