poojavb 29 Junior Poster

Just displaying code is not enough for us to understand ur problem....do explain ur problem in detail...

poojavb 29 Junior Poster

May be u shud post this code under jsp section....

in this section we can help u with queries

poojavb 29 Junior Poster

display the receipt using crystal report....it wll hold all the data....but those values shud be present in database...

to calculate sum, the function is also available in reports...u can use it

poojavb 29 Junior Poster

U can paste ur solution so that it would be helpful for someone else who need the same....

poojavb 29 Junior Poster

u can also try to first clear the combo box items before adding the values to it....

poojavb 29 Junior Poster

Check which is ur startup form....if ur startup form is the same as the one u r closing then it will close the complete application....

dont use the me.close or me.dispose....use Me.Hide and try....

to check ur startup form click on Project -> Projectname properties -> Application tab -> Startup form

poojavb 29 Junior Poster

checkbox1 - name
checkbox2 - date

give conditions in such a way that

if checkbox1.checked = true then
'ur sql query which will show the result in datagridview
elseif checkbox2.checked = true then
'ur sql query
elseif checkbox1.checked = true and checkbox2.checked = true then
'ur sql query
else 'means if both are unchecked then display error or if u want to display all details of the table
'whatever u need
End if
M.Waqas Aslam commented: very nice one , Pooja , simple and clear. +4
poojavb 29 Junior Poster

Please could you explain in detail....what problem are u actually facing....

poojavb 29 Junior Poster

prompt means display the form name which is showing the error.

Yes I have changed the string to boolean....

ok i will tell u in easy words....

I have one form say frmPatientRegister in which I need the connection string

module DBConnection

when the connection will fail it will contain false which will be passed to the module fail connection i.e. catch block...so I also want it to return the form name...

how to do that??

poojavb 29 Junior Poster

Hello Friends....One more doubt...

I have a connection module in which I have written the open and close database connection....

if database connection is an error it will return false else if success it will return true

the function of the modules will be called from the form code....

what I need is if the connection is an error the module should also get the form name which returned the error...is it possible???

check my below code....

DBConnection.module

Imports System.Data.SqlClient

Module DBConnection
    Public Connection As SqlConnection = New SqlConnection()
    Public Function Open_DB_Connection() As String
        Try
            Connection.ConnectionString = "Data Source = LocalHost\;Initial Catalog = Database;Integrated Security  = True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            MsgBox("Connection Error: " + ex.Message)
            Return "Fail"
            Exit Function
        End Try
    End Function

    Public Function Close_DB_Connection() As String
        Try
            Connection.Close()
            Return "Success"
        Catch ex As Exception
            MsgBox("Connection Error: " + ex.Message)
            Return "Fail"
            Exit Function
        End Try
    End Function
End Module

Call from the function is this way....

Dim Open_DB_Con As String
Dim Close_DB_Con As String

Open_DB_Con = Open_DB_Connection()

'other stuff required like queries....

Close_DB_Con = Close_DB_Connection()

now what I need is if the functions Open_DB_Connection() or Close_DB_Connection() returns error it should prompt the form name....

is it possible?? to code it in module....

thanks for help in advance....

poojavb 29 Junior Poster

No I just want time...

from datetimepicker1 i have time and in ms sql also time....but I am not able to get the data from database to picker...

poojavb 29 Junior Poster

Begginnerdev - This will be for the forms size...

can u tell me if controls will be placed accordingly....if the screen is maximized or minimized???

I guess only flowlayoutpanel will do this...

poojavb 29 Junior Poster

select * will show all the rows....if u r mentioning some column names then it wont show??

what query are u using??? and what rows do u want to return??? paste it....

poojavb 29 Junior Poster

try giving distinct keyword for all the three columns....

poojavb 29 Junior Poster

Hello Friends,

I have a doubt....

Can we set the windows form resolution according to pc screen resolution
and even the control should be adjusted....is it possible???

eg.

My screen resolution is 1366 X 768

and my form size is 1254, 709....but I want it so set according to the screen and it will be dynamic...

if I transfer my project to some other pc with lower or higher resolution it should be adjusted....

and suppose I have few controls on the form...will that also be adjusted???

please do let me know....

thanks in advance...

poojavb 29 Junior Poster

Please explain in details....
when are u getting this error?? what is the object related to this error???

poojavb 29 Junior Poster

For deleting data with the help of datagridview and updating in access u can use

'Open connection
   Dim i As Integer
    Dim ID As String
    i = DatagridView1.CurrentRow.Index
    ID = DatagridView1.Item(0, i).Value 'whichever will be primarykey or unique data
      Try
        Dim MessageText As String
        Dim myCommand As OleDbCommand
        myCommand = New OleDbCommand("Delete from tablename where colname='" + ID + "'", Connection)
        Dim DBReader As OleDbDataReader = myCommand.ExecuteReader
        DBReader.Close()
      Catch ex As Exception
        MsgBox("Error in delete query: " + ex.Message)
      End Try
'then show the updated datagridview again

Hope this helps

poojavb 29 Junior Poster

The above query will show BidTime as Desc and BidAmount as Asc....

But according to the criteria

  1. Assign Highest Rank of based on Max BidAmount.

  2. If Bid Amount gets tie with other user then who ever enter bid amount first he will get the high Rank

So just use the opposite of what darkagn as given

SELECT RANK() OVER (ORDER BY vcBidAmount DESC, vcBidTime) AS Ranking,
*
FROM BiddingTable

Hope this is what pritesh2010 wants....

poojavb 29 Junior Poster

Are you looking for this??

    Private Sub DataGridView1_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim i As Integer
        i = DataGridView1.CurrentRow.Index
        Form1.TextBox1.Text = DataGridView1.Item(1, i).Value.ToString
        Form1.TextBox2.Text = DataGridView1.Item(2, i).Value.ToString
    End Sub

Ohhh...sorry...this code is in vb.net....

poojavb 29 Junior Poster

You dont have to make any changes there...

while creating parameters....just enter the parameter name and the datatype type...and nothing....

Still in the Value options if you want the values
Allow discrete values - > True
allow range value -> false
allow multiple values ->false

poojavb 29 Junior Poster

Please explain ur problem in detail....only showing the code might not help....

poojavb 29 Junior Poster

I guess if u post this in ASP.net u might get some help....

poojavb 29 Junior Poster

Whatever Jim has given it works...add few more lines of code

Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click 'checked on button click
    Dim found As Boolean = InListView(ListView1, ComboBox1.Text)
    If found = True Then
        MsgBox("Exists")
    Else
        'MsgBox("No")
        ListView1.Items.Add(ComboBox1.Text)
    End If
End Sub

Private Function InListView(lvw, text) As Boolean
    For Each item As ListViewItem In lvw.items
        If item.Text = text Then Return True
    Next
    Return False
End Function
poojavb 29 Junior Poster

you forgot the word Add....

it shud be Listview1.Items.Add and then the reader....

    Try
        Dim myCommand As SqlCommand
        myCommand = New SqlCommand("SELECT  * FROM DoctorRegister ", Connection)
        Dim reader As SqlDataReader = myCommand.ExecuteReader
        While reader.Read
            ListView1.Items.Add(reader.Item("FirstName")).Selected = True
        End While
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

selectedItem is not the property for listview.....

ListView1SelectedItem = reader.Item("PERSON")

poojavb 29 Junior Poster

from date and two date will be the two parameters in crystal reports in which ur crystal report will show the data in that range.....

poojavb 29 Junior Poster

set a masked Text box and set the mask as 00,000,000 and the database datatype can be varchar to retrieve this data....hope it helps u....

poojavb 29 Junior Poster

if u want a clear cell that use "" instead of Test4...

It will be good enough if u be more specific....n number of people will be able to help u....

poojavb 29 Junior Poster

Hey thanks...it worked perfectly fine...even I needed the same....Thanks _avd

poojavb 29 Junior Poster

you can create a module and then call the module whenever u need a database connection....

this will help you to update the changes in your database only once if u need to change it anytime in future,,,,else u need to change in each and every line if u dont create a module....

Module

Imports System.Data.SqlClient
Module Module1
       Public Connection As SqlConnection = New SqlConnection()
    Public Function Open_DB_Connection() As String
        Try
            Connection.ConnectionString = "Data Source = LocalHost\;Initial Catalog = Databasename;Integrated Security  = True"
            Connection.Open()
            Return "Success"
        Catch ex As Exception
            Return "Fail"
            Exit Function
        End Try
    End Function

    Public Function Close_DB_Connection() As String

        Try
            Connection.Close()
            Return "Success"
        Catch ex As Exception
             Return "Fail"
            Exit Function
        End Try

    End Function
End Module

when u need to call the database in your code...then call as

    'Open connection
         Dim Open_DB_Con As String
        Dim Close_DB_Con As String
        Open_DB_Con = Open_DB_Connection()
        If Open_DB_Con = "Success" Then
            Debug.Print("Database connection sucessfull")
        ElseIf Open_DB_Con = "Fail" Then
            MsgBox("Could not establish DataBase connection! ")
        End If

    Try
        Dim myCommand As SqlCommand
        myCommand = New SqlCommand("select * from Test", Connection)
        Dim DBReader As SqlDataReader = myCommand.ExecuteReader
        While DBReader.Read
           Label1.Text = DBReader("colname")
        End While
        DBReader.Close()
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

'closing connection
    Close_DB_Con = Close_DB_Connection()
    If Close_DB_Con = "Success" Then
        Debug.Print("Database connection closed")
    ElseIf Close_DB_Con = "Fail" Then
        MsgBox("Could not close DataBase connection! ")
        Debug.Print("Could not close DataBase connection! ")
    End If

Hope this helps....

poojavb 29 Junior Poster

you had said that u

connected Crystal Report to Crystal Report Viewer i.e. the connection is done through the small arrow we can see on the crystal report viewer.

actually that is not needed....

in ur rpt files.....there are two tabs....below....

  1. Main Report Preview
  2. Main Report....

Check whether u r able to get the report in ur Preview window....if yes means crystal report is correct and ur vb.net coding is wrong....

poojavb 29 Junior Poster

Mitja - when I copied ur code I get an error that 'Class 'System.Windows.Forms.DataGridViewRow' cannot be indexed because it has no default property.'

See what I have done in my code.....

  Try
            Dim myCommand As SqlCommand
            myCommand = New SqlCommand("SELECT  * FROM PurchaseOrder ", Connection)
            Dim dt As New DataTable
            dt.Load(myCommand.ExecuteReader)
            If dt.Columns.Count <= 0 Then
                MsgBox("No records found")
            Else
                With DataGridView1
                    .AutoGenerateColumns = True
                    .DataSource = dt
                End With
            End If
            For Each row As DataGridViewRow In DataGridView1.Rows
                If row("ConditionColumnName").Value.ToString() = "your condition" Then
                    row.[ReadOnly] = True
                    'you can even color the row differently
                    'like:
                    row.DefaultCellStyle.BackColor = Color.Red
                Else
                    row.[ReadOnly] = False
                    'normal color
                    row.DefaultCellStyle.BackColor = Color.White
                End If
            Next
        Catch ex As Exception
            'Debug.Print("Exception: ")
            Throw ex
        End Try
poojavb 29 Junior Poster

to pass the value in combo box u can use....

 Dim conn As New SqlConnection(ConnectionString)
        Dim strSQL As String = "your sql query"
        Dim da As New SqlDataAdapter(strSQL, conn)
        Dim ds As New DataSet
        da.Fill(ds, "Tablename")
        With ListBox1
            .DataSource = ds.Tables("Tablename")
            .DisplayMember = "ColumnName" 'column name to be displayed in combo box
            .SelectedIndex = 0
        End With
poojavb 29 Junior Poster

the below thing I had done in my change password code...check if this helps u....
this code I had written in a button click event....

'Open connection

        If txtUName.Text = "" Or txtOldPwd.Text = "" Or txtNewPwd.Text = "" Or txtCNPwd.Text = "" Then
            MsgBox("All fields are mandatory")
        Else
            If txtNewPwd.Text <> txtCNPwd.Text Then
                MsgBox("Password and Confirm Password should be same")
                txtCNPwd.Text = ""
                txtNewPwd.Text = ""
                txtNewPwd.Focus()
            Else
                Try
                    Dim myCommand As SqlCommand
                    myCommand = New SqlCommand("Select Username, password from userdetails where Username='" + txtUName.Text + "' and password='" + txtOldPwd.Text + "'", Connection)
                    Dim reader As SqlDataReader = myCommand.ExecuteReader
                    Dim value As Boolean
                    value = reader.Read
                    reader.Close()
                    If value = True Then
                        Try
                            Dim myCommand2 As SqlCommand
                            myCommand2 = New SqlCommand("update userdetails set password='" + txtNewPwd.Text + "' where username='" + txtUName.Text + "'", Connection)
                            myCommand2.ExecuteNonQuery()
                            MsgBox("Password Changed Successfully")
                            Me.Close()
                        Catch ex As Exception
                            MsgBox("Error in select query: " + ex.Message)
                        End Try
                    Else
                        MsgBox("Old password is incorrect")
                        txtCNPwd.Text = ""
                        txtNewPwd.Text = ""
                        txtOldPwd.Text = ""
                        txtOldPwd.Focus()
                    End If
                Catch ex As Exception
                    MsgBox("Error in select query: " + ex.Message)
                End Try
            End If
        End If

       'close connection
poojavb 29 Junior Poster

Not enough....be more clear and precise....

poojavb 29 Junior Poster

Hello Friends,

One help is required....

I have a select query which is based on two criterias....

if the order is in process or if the order is received....

The datagridview will show all the records from the database,,,,

I want to disable the rows in datagridview which will be in received status...only the on order should be editable....

is it possible???

please do help me in this...

Thanks in advance....

poojavb 29 Junior Poster

Duplicate thread Click Here

poojavb 29 Junior Poster

Hey Iamateur is your report working fine???

poojavb 29 Junior Poster

Please post the query in Database section....This is VB.net section

poojavb 29 Junior Poster

I tried my best...may be someone else will be able to help u....sorry

poojavb 29 Junior Poster

check ur parameter names in code and in crystal report....it shud be the same.....

fromdate
todate

also check the dateformat in SQL database the date datatype saves in yyyy-MM-dd format.....

make use of date format only in SQL database and when creating a parameter use a string...it worked for me....

poojavb 29 Junior Poster

BitBlt - U are just superb....thanks a lot....

let me tell u all in brief....actually I did not go for one table since if anyone opens the database then it is difficult to get the outpatient and inpatient.....

So I made two different table for inpatient and outpatient....so that it is easy to find the data.....it may be stupidity but I had to do it .... :)

poojavb 29 Junior Poster

Did u check the attachment??

poojavb 29 Junior Poster

No.....Inpatient means that patient who will have a stay in the hospital....

outpatient means just have come for testing and leaves the same day....

both are different.....

ChrisHunter - join cannot be applied as the ID's are different...it wont be same anytime.....both the inpatient and outpatient are different....

poojavb 29 Junior Poster

Check the attached project....

database back up file is also attched with it....its is an SQL server database....so restore it correctly.....

poojavb 29 Junior Poster

Let me tell u in detail....

  1. Create a crystalreport for ur project...... eg. Crystalreport.rpt
  2. After the report is created create parameters as I told u....fromdate and todate and then avail the condition in the Record Selection Editor Formula as ur database_columnname in {fromdate} to todate
  3. Go to ur Main Report Preview Window and see if u are getting ur output....the report will have two textboxes as from date and to date then enter the value and see if u get ur output....

this deals with ur crystal report...

Now ur win form.....

Add two datetimepickers for fromdate and todate.....one button to show the report and one crystal report viewer....

in ur button click event write the code which I had given u earlier and give the correct database and the correct crystal report path....

Run ur program and then see what output u get.....

to need to connect ur crystal report to crystal report viewer as u said in point 2....

Check and let me know if still u face any error....

poojavb 29 Junior Poster

Too weird but still I have a doubt....

I have two table....
-> OutpatientDetails
-> InpatientDetails

But the fieldnames are same except for the ID....i.e. OutPatientID and InPatientID respectively.....

I want to combine both the tables and produce one output.....I dont know whether it is possible or no....

I want the doctors to see both the data simulataneously...

like

PatientID | PatientFName | PatientLName | Gender
------------------------------------------------
INP1      | ABC          | XYZ          | Female    -this is an inpatient
OTP1      | DEF          | PQR          | Male      -this is an outpatient

Is it possible to get the query this way.....

do let me know....

Thanks in advance.....

poojavb 29 Junior Poster

Can u please show ur save event??

poojavb 29 Junior Poster

write below code in ur button click event
textbox2 is the field where u will enter number

  MsgBox(ConvertNum(TextBox2.Text))

Then write the below function

 Public Shared Function ConvertNum(ByVal Input As Long) As String 'Call this function passing the number you desire to be changed
        Dim output As String = Nothing
        If Input < 1000 Then
            output = FindNumber(Input) 'if its less than 1000 then just look it up
        Else
            Dim nparts() As String 'used to break the number up into 3 digit parts
            Dim n As String = Input 'string version of the number
            Dim i As Long = Input.ToString.Length 'length of the string to help break it up

            Do Until i - 3 <= 0
                n = n.Insert(i - 3, ",") 'insert commas to use as splitters
                i = i - 3 'this insures that we get the correct number of parts
            Loop
            nparts = n.Split(",") 'split the string into the array

            i = Input.ToString.Length 'return i to initial value for reuse
            Dim p As Integer = 0 'p for parts, used for finding correct suffix
            For Each s As String In nparts
                Dim x As Long = CLng(s) 'x is used to compare the part value to other values
                p = p + 1
                If p = nparts.Length Then 'if p = number of elements in the array then we need to do something different
                    If x <> 0 Then
                        If CLng(s) < 100 Then
                            output = output & " And " & …
poojavb 29 Junior Poster

check ur database connection

poojavb 29 Junior Poster

For anyone who might need it

'Open connection
        Try
            Dim myCommand As SqlCommand
            myCommand = New SqlCommand("SELECT * FROM tablename where Day(BirthDate)='" + Date.Now.Day.ToString + "' and Month(Birthdate) = '" + Date.Now.Month.ToString + "'", Connection)
            Dim reader As SqlDataReader = myCommand.ExecuteReader
            Dim bool As Boolean
            bool = reader.Read
            reader.Close()
            If bool = False Then
                MsgBox("Invalid details")
            Else
                Dim dt As New DataTable
                dt.Load(myCommand.ExecuteReader)
                With DataGridView1
                    .AutoGenerateColumns = True
                    .DataSource = dt
                End With
            End If
            reader.Close()
        Catch ex As Exception
            MsgBox("Error Connecting to Database: " & ex.Message)
        End Try
close connection