poojavb 29 Junior Poster

Ur welcome.....vote me up :) and mark the thread as solved if it helped u....

poojavb 29 Junior Poster

Ur welcome.... dont forget to vote me up :) and mark the thread as solved if it helped u....

poojavb 29 Junior Poster

Hello Friends,

I need to develop a birthday reminder form in my project....

The list of all patient that are celebrating birthday on that particular day and month...leaving the year....

My database is SQL server and I have used date datatype for it....

So I can I get the month and the day from the query and show the list of patient celebrating birthday in a datagrid.....

poojavb 29 Junior Poster

I had a datatype date in my database that is Microsoft SQL server....and so I had used a string datatype in crystal report....it worked for me....

and even vice versa...when varchar in database then date datatype in crystal report.....

Might be u are missing something.....

poojavb 29 Junior Poster
select a.item_number, a.itemdesc,c.colordescription,m.monthdescription from article a, colors c , month m where a.colornumber=c.colornumber and a.monthnumber=m.monthnumber
poojavb 29 Junior Poster

check the datatype values in database and the parameter datatype that u have created.. else try putting quotes for ur parameters in the Record Selection Formula Editor

poojavb 29 Junior Poster

I have one parrot- Mitthi, 5 fishes and one dog - Buzo

poojavb 29 Junior Poster

U must have created a crystal report using the wizard right???

That is ur crystal report....in that now u need to compare the value with crsytal report

means

the datetimepicker1 and two are ur part of vb.net code so there shud be some parameters to compare with the crystal report...

1. Open ur crystalreport1.rpt file 'dont know ur file name...
2. On left had side u will have a Field Explorer window...Right click on Parameter Fields-> New -> create two variables as fromdate and todate with datatype String.....

after this is done u need to assign the parameter values to that of ur table column ida since that contains ur date values....

1. on center of ur crystal report right click -> Report -> Selection Formula - >Record
2. A Record Selection formula Editor window will be opened ...write the below thing according to ur requirements
3. {tablename.ida} in {?fromdate} to {?todate}

this will compare in ur crystal report....

rutuja8 commented: hey when we close the record selection formula editor the error is occruing......................i applied ur replies also bt was of no use error is popping out..........pls reply me as sun as pos +0
poojavb 29 Junior Poster

Y are u validating the condition again....its the same thing that the query will give u...just show the datagrid with the result as I have shown....

ElseIf ((dr(0).ToString() >= TextBox1.Text) And (dr(0).ToString() <= TextBox2.Text)) Then

 Try
                Dim myCommand As New SqlCommand
                With myCommand
                    .CommandText = "select * IssueMBA WHERE ida between '" + TextBox1.Text + "'and  '" + TextBox2.Text + "'"
                   .CommandType = CommandType.Text
                    .Connection = Conn
                End With
                Dim dt As New DataTable
                dt.Load(myCommand.ExecuteReader)
                With DatagridView1
                    .AutoGenerateColumns = True
                    .DataSource = dt
                End With
            Catch ex As Exception
                Throw ex
            End Try

instead of writing select count(*) write the column names that u need in ur datagridview

poojavb 29 Junior Poster

no crvIssueMBA should be ur crystal report viewer name....see my example....cryRpt is my crystalreportviewer name.....

have u added this below code??

Dim cryRpt As New ReportDocument
cryRpt.Load("crystal report complete path")

cryRpt the place where u have ur actual crystal report....complete path

poojavb 29 Junior Poster

Can u show us ur code so that we can find out where u are going wrong....

poojavb 29 Junior Poster

Write the event in combobox1 selectediIndex change event...make correct connections

Try
   Dim myCommand As New SqlCommand
   With myCommand
        .CommandText = "SELECT ordernumber,orderdate,itemname,quantity,RepairNumber FROM orderstable WHERE OrderNumber = '" & ComboBox1.Text & "'"
        .CommandType = CommandType.Text
        .Connection = conn
   End With
   Dim dt As New DataTable
   dt.Load(myCommand.ExecuteReader)
   With DatagridView1
        .AutoGenerateColumns = True
        .DataSource = dt
   End With
Catch ex As Exception
   Throw ex
End Try
poojavb 29 Junior Poster

use a masked textbox and set the setmask property accordingly

poojavb 29 Junior Poster

Find ur ansers below

  1. Yes u can add ur cystal report in the same form where u have added the crystal report viewer and the datetimepickers...
  2. crtableLogoninfos - this is because when u move ur database to anyother client machine then the server name may change according to the client and also the database...to get the correct database info I have added the above code

Yes according to ur form it may be the same as below but check that the date format is the same as u have ment0ined in the query.....it changes according to the database

myCommand = New SqlCommand("select * from IssueMBA where ida between '" + DateTimePicker1.Value.ToString("MM-dd-yyyy") + "' and '" + DateTimePicker2.Value.ToString("MM-dd-yyyy") + "'", con)

  1. Check if the datetimepicker name is the same as u are giving in ur query

crParameterDiscreteValue.Value = DateTimePicker1.Value.ToString("MM-dd-yyyy")

  1. Same as 3.

Note:
u have the below line also in ur code....
crParameterFieldDefinition = crParameterFieldDefinitions.Item("todate")

the todate and the fromdate are the paramaters that has to be created while creating ur crystal reports....

if u have any doubt feel free to post...

Please check my attachment...

poojavb 29 Junior Poster
cmd = New SqlCommand("SELECT COUNT(*) FROM IssueMBA where ida between '" + textbox1.text + "' and '" + textbox2.text + "'")

after between '=' sign wont come....

poojavb 29 Junior Poster

yes it will be better if u have one column only for date so that u can aslo use the between case

poojavb 29 Junior Poster

Please be more specific...

poojavb 29 Junior Poster

try the below text for all the textboxes keypress event...

   'accepts only numbers
    If (Microsoft.VisualBasic.Asc(e.KeyChar) < 48) Or (Microsoft.VisualBasic.Asc(e.KeyChar) > 57) Then
        e.Handled = True
    End If
    If (Microsoft.VisualBasic.Asc(e.KeyChar) = 8) Then
        e.Handled = False
    End If

This will be too lengthy I guess...coz u will have to code for all 20 text boxes key press....

else create a function similar to it and call the function in key press event

poojavb 29 Junior Poster

Try if the below code works fro u....

con.Open()
cmd = New SqlCommand("SELECT COUNT(*) FROM IssueMBA WHERE ida='" + TextBox1.Text + "' and rda='" + TextBox2.Text + "'", con) 'here u are giving and condition and not between check one....

dr = cmd.ExecuteReader()
If Not dr.Read() Then
MsgBox("Invalid details")
Else
 Dim dt As New DataTable
     dt.Load(myCommand.ExecuteReader)
     With DatagridView1
           .AutoGenerateColumns = True
            .DataSource = dt
     End With
End If
poojavb 29 Junior Poster

The save data code is given in the above thread....

Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsave.Click
Dim con As New SqlClient.SqlConnection
Dim com As New SqlCommand
Dim adap As New SqlDataAdapter
Dim ds As New DataSet
con = New SqlConnection("data source=niqotine;initial catalog=record;uid=sa;pwd=mindworks")
con.Open()
com.CommandText = "insert into UserInfo values('" + txtname.Text + "','" + txtid.Text + "','" + cmbcolor.Text + "')"
com.Connection = con
com.ExecuteNonQuery()
adap = New SqlDataAdapter("select * from UserInfo", con)
adap.Fill(ds, "1")
DataGridView1.DataSource = ds.Tables("1")
End Sub

give a try to it...

the code says that u are adding the details in text box combox box and other different controls of the form and then displaying thr data is data grid view

poojavb 29 Junior Poster

Try using masked text box and set the setmaskproperty as you want

poojavb 29 Junior Poster

if user clicks on X button call the save_click event in the form_formclosing event....
before that u can ask the user with a msg box whether the user wants to save the form or just close without saving.....if user wants to save call the save event else dispose the form...

chrck below

write the below event for ur form1_formclosing

Dim dr As Object
    If e.CloseReason = CloseReason.UserClosing Then
       dr = MsgBox("Do you want to save the changes?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question)
       If dr = vbYes Then
          Me.Dispose()
          e.Cancel = False
       Else
          btnSave(sender,e)
    End If
End If
poojavb 29 Junior Poster

u can use a datetimepicker to show the from date and to date....

I will give my example to u...

I have one form in which I have two datepickers one for from date and the other one to date...one button to close the form and the second one to show the report....

u also need a crystal report viewer to display the report which will be under the reporting tab....

now check my code behind form....

NOTE: JUST for reference

Imports System.Data.SqlClient
Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine

Public Class frmInpatientmasterreport

    Private Sub btnShow_Click(sender As System.Object, e As System.EventArgs) Handles btnShow.Click
        'connection string goes here
        If dtpFromDate.Value > dtpToDate.Value Then
            MsgBox("From Date cannot be greater than To Date")
        Else
            Try
                Dim myCommand As SqlCommand
                myCommand = New SqlCommand("select * from HMS.dbo.inpatientdetails where createddate between '" + dtpFromDate.Value.ToString("yyyy-MM-dd") + "' and  '" + dtpToDate.Value.ToString("yyyy-MM-dd") + "'", Connection)
                Dim reader As SqlDataReader = myCommand.ExecuteReader
                If reader.Read = True Then
                    Dim crtableLogoninfos As New TableLogOnInfos
                    Dim crtableLogoninfo As New TableLogOnInfo
                    Dim crConnectionInfo As New ConnectionInfo
                    Dim CrTables As Tables
                    Dim CrTable As Table

                    Dim cryRpt As New ReportDocument
                    cryRpt.Load("crystal report complete path")

                    With crConnectionInfo
                        .ServerName = "servername"
                        .DatabaseName = "Database"
                        .UserID = ""
                        .Password = ""
                        .IntegratedSecurity = True
                    End With
                    CrTables = cryRpt.Database.Tables
                    For Each CrTable In CrTables
                        crtableLogoninfo = CrTable.LogOnInfo
                        crtableLogoninfo.ConnectionInfo = crConnectionInfo
                        CrTable.ApplyLogOnInfo(crtableLogoninfo)
                    Next
                    Dim crParameterFieldDefinitions As ParameterFieldDefinitions
                    Dim crParameterFieldDefinition As ParameterFieldDefinition
                    Dim crParameterValues As New ParameterValues
                    Dim crParameterDiscreteValue As New ParameterDiscreteValue

                    crParameterDiscreteValue.Value = **dtpFromDate.Value.ToString("yyyy-MM-dd")**
                    crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
                    crParameterFieldDefinition = …
poojavb 29 Junior Poster

After else if u need to mention the condition and then continue with the code....if no condition is present then just use else

show the exact code what u have done after adam_k has post so we can help u more on it...

poojavb 29 Junior Poster
 Dim b As Integer = CInt(TextBox2.Text)
 Dim c As Integer = CInt(TextBox3.Text)
 Dim a As Integer = b * c
 MsgBox(a)
poojavb 29 Junior Poster
 Dim BornDate As Date = DateTimePicker3.Value
 Dim Interval As TimeSpan = Now - BornDate
 Debug.Print("Interval: " + Interval.TotalDays.ToString)
 Dim years As Integer = Math.Truncate(Interval.TotalDays / 365)
 TextBox1.Text = years

This part will return exact one year difference if true
'datetimepicker3 is the value that will be changing
it has been compared with Todays date....

poojavb 29 Junior Poster

write the following code in ur product combobox selection changeevent as below

    Dim conn As New SqlConnection(ConnectionString)
    Dim category As String
    category = cboCategory.Text
    Dim strSQL As String = "SELECT pt.productidID,pt.ProductName FROM ProductTable pt, categoryTable ct where ct.CategoryName='" & category & "' and pt.categoryid=ct.categoryid"
    Dim da As New SqlDataAdapter(strSQL, conn)
    Dim ds As New DataSet
    da.Fill(ds, "ProductTable")
    With cboDoctorID
        .DataSource = ds.Tables("ProductTable")
        .DisplayMember = "ProductnameName"
        .ValueMember = "productidID"
        '.SelectedIndex = 0
    End With
poojavb 29 Junior Poster

thank u very much Reverend Jim

poojavb 29 Junior Poster

Is fullname alos a columnname in the table or just an alias u r giving to the concatenation of fname and lname

if it is a column name then I guess it wont go into the column else if it an alias then try below code

SELECT DISTINCT DEV_user_registration.reg_fname + ' ' + DEV_user_registration.reg_lname AS 'Fullname'
FROM DEV_user_registration
WHERE DEV_user_registration.reg_agent = 'Yes'
AND DEV_user_registration.reg_fname + ' ' + DEV_user_registration.reg_lname = '$_GET[agent_name]' ";

I guess it shud be this way

poojavb 29 Junior Poster

if these are the only fields in ur table client then y use the field name just use the parameters
one mistake is u shud use datetimepicker1.value and not text

Give a try

Try
   Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = C:\projet.mdb"
   Dim Save As OleDbCommand
   Save = New OleDbCommand("INSERT INTO Client("'+TextBox1.Text+'","'+ TextBox2.Text+'", "'+ TextBox3.Text+'", "'+TextBox4.Text+'",'"DateTimePicker1.Value+'")", ConStr)
   Dim DBReader As OleDbDataReader = Save.ExecuteReader
   DBReader.Close()
Catch ex As Exception
   Exit Sub
End Try
poojavb 29 Junior Poster

Thank u all for ur help....

Reverend Jim - Can the expression which u have given be converted to one and then be applied on textbox validating event that will prompt the error....

see my example that I have done for email....can the same be applied to password....

     Private Sub txtEmailID_Validating(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles txtEmailID.Validating
        If txtEmailID.Text <> "" Then
            Dim rex As Match = Regex.Match(Trim(txtEmailID.Text), "^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$", RegexOptions.IgnoreCase)
            If rex.Success = False Then
                ErrorProvider1.SetError(txtEmailID, "Please Enter a valid Email-Address")
                txtEmailID.Focus()
                Exit Sub
            Else
                ErrorProvider1.Clear()
            End If
        End If
    End Sub
poojavb 29 Junior Poster

seslie - I tried ur query but it returned the rows only if patientid is present in Insurance details table

darkagn - Your query worked absolutely fine....

Thank you both for ur help

poojavb 29 Junior Poster

Hello Friends,

I have three table
->PatientDetails
->ParentDetails
->InsuranceDetails

-Patient id is the common column in all the three tables...

While saving the data in table using VB.Net there is a column in PatientDetails i.e. Insured

If the patient is insured then only the values from text boxes and the patient id will be saved in InsuranceDetails Table else the patientid wont exist in that table

But I want to retrieve data from all the three tables even if the patient is not insured the blank columns shud be atleast shown to the user

for that I had written a query as below but it is not showing any values

please check my query and help me on this...I just used a join for patientid

select 
    ipd.InPatientID,
    ipd.Fname+' ' +ipd.LName as 'Patient Name' ,
    ipd.Gender,
    ipd.BirthDate,
    ipd.AccType as 'Account Type',
    ipd.Minor, 
    ipg.GFName+' ' +ipg.GLName as 'Guardian name',
    ipd.Insured,
    ipi.Insurance1,
    ipi.Policy1,
    ipi.GroupNo1, 
    ipi.Guarantor,
    ipi.Employer 
from 
    HMS.dbo.PatientDetails ipd, 
    HMS.dbo.ParentDetails ipg, 
    HMS.dbo.InsuranceDetails ipi 
where 
    ipd.InPatientID=ipg.InPatientID or 
    (ipd.InPatientID=ipi.InPatientID and 
    ipi.InPatientID=ipg.InPatientID)

Please provide some help on this....

Thanks in advance

poojavb 29 Junior Poster

sorry special characters like !@#$%^&*()

poojavb 29 Junior Poster

what type of database are u using....coz the query is different in SQL and access

poojavb 29 Junior Poster

check if ur form2 dataset is returning any rows or no.....

poojavb 29 Junior Poster

to display data in the datagrid use the below code and then call the method with datagridview
Note- in select query call only the fields that u want to display in your datagridview1

Public Function GetData() As DataView
        'open connection
        Dim SelectQry = "SELECT * FROM Pricelist WHERE [SECURITY] ='" & Me.cboCompany.SelectedItem & "'"
        Dim SampleSource As New DataSet
        Dim TableView As DataView
        Try
            Dim SampleCommand As New SqlCommand()
            Dim SampleDataAdapter = New SqlDataAdapter()
            SampleCommand.CommandText = SelectQry
            SampleCommand.Connection = Connection
            SampleDataAdapter.SelectCommand = SampleCommand
            SampleDataAdapter.Fill(SampleSource)
            TableView = SampleSource.Tables(0).DefaultView
        Catch ex As Exception
            Debug.Print("Exception: ")
            Throw ex
        End Try
       'close connection
        Return TableView
    End Function

and when calling datagrid write the following code like in button click or form load event...

Datagridview1.DataSource = GetData()

Hope this helps you

poojavb 29 Junior Poster

As it is a number datatype a null value wont be stored in the column....it will store 0 as null value....

change it to text and then u can save a null value....

thines01 commented: Good catch! +12
poojavb 29 Junior Poster

I dont want to check if its strong or no but when the user will enter the details in the textbox I want to make sure that he/she wont enter wrong data....

eg my criteria for password is as follows

range between 8 to 15
atleast one uppercase character ,
atleast one number ,
atleast one lower case character
and only one special case character

consider for special case....
only one special case is allowed....so if the validating event finds two or more it should prompt that the entry is wrong,,,,

poojavb 29 Junior Poster

You can do one thing....Give user the option for preview so that he/she can make settings and similarly print the form....

poojavb 29 Junior Poster

Please can u explain more in detail

poojavb 29 Junior Poster

Is your splash screen the startup form??? if so try to make it as visible= false....
if it is a start up form and u try to close the splash screen then the complete application will exit,,,

poojavb 29 Junior Poster

So I had answered above....did it help you...
Click Here

poojavb 29 Junior Poster

The Print form control is there in the Visual Basic PowerPacks toolbox

To print the complete client area of a scrollable form
1.In the Toolbox, click the Visual Basic PowerPacks tab and then drag the PrintForm component onto the form.

The PrintForm component will be added to the component tray.

2.In the Properties window, set the PrintAction property to PrintToPrinter.

3.Add the following code in the appropriate event handler (for example, in the Click event handler for a Print Button).

PrintForm1.Print(Me, PowerPacks.Printing.PrintForm.PrintOption.FullWindow)
poojavb 29 Junior Poster

Open file dialog box has a property to open multiple files openFileDialog1.Multiselect = true

poojavb 29 Junior Poster

U can directly use the text boxes instead of using property

just giving an example

If I want a value from form1 to form2 then I use following way

code in form1

Textbox1.Text=Form2.Label1.Text

In this way it wont open a new form....In your code u have used

Dim obj As New Form2

so u are getting a new form...just pass variables with form instead of creating property and also u can call the hide() and show() methods of the form

poojavb 29 Junior Poster

U r getting it wrong....
there are two places where I need the regular expressions.....

for password I want a strong password with following criteria

range between 8 to 15
atleast one uppercase character ,
atleast one number ,
atleast one lower case character
and only one special case character

for username I want only alphabets....

only lower case characters (min 8 - max 15)

I hope I am clear now.....please help me to create this regular expression.....

poojavb 29 Junior Poster

Hello Friends...

I need help on regular expressions....

I tried the following way but it did not work for me....please help me to create a regular expression...

^.*(?=.{8,})(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(^[a-zA-Z0-9@\$=!:.#%]+$)

My requirement is
-> Min 8 to 15 characters - this I will do with the length validation or by including in the regex
->
atleast one uppercase character ,
atleast one number ,
atleast one lower case character
and only one special case character

other requirement is
-> only lower case characters (min 8 - max 15) Regular Expression - [a-z]{8,15}

Please let me know if I am correct else please correct me....

poojavb 29 Junior Poster
  TextBox1.Text = DateTimePicker3.Value + " " + DateTimePicker4.Value

Note - DateTimepicker3 has date and Datetimepicker4 has time in it....the value will be displayed in textbox4...and the datetimepicker values are separated by a space

check if u needed the same....

poojavb 29 Junior Poster

Since I dont want date first i tried with the Time datatype in mssql and then later with varchar...but both did not work out....