i have a project in my last year and have 2 queries

i am using vb.net and sql server 2005 as backend
first problem is, i have a search form in which a field called billno is searched and all details are displayed in datagridview but the problem is i have to restart the project every now and then.whenever any entry is done in database the immediate form opens is the search form so it must display the data which was inserted immediately without restarting the project.

for inserting data i am using the following code :

f TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or TextBox7.Text = "" Or TextBox11.Text = "" Or TextBox12.Text = "" Or TextBox13.Text = "" Or DateTimePicker1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Enter Proper Details")
ErrorProvider2.SetError(TextBox2, "Enter Proper Details")
ErrorProvider3.SetError(TextBox3, "Enter Proper Details")
ErrorProvider4.SetError(TextBox7, "Enter Proper Details")
ErrorProvider5.SetError(TextBox11, "Enter Proper Details")
ErrorProvider7.SetError(TextBox12, "Enter Proper Details")
ErrorProvider8.SetError(TextBox13, "Enter Proper Details")
ErrorProvider9.SetError(DateTimePicker1, "Enter Proper Details")

Dim constr As String
constr = "Data Source=.\SQLEXPRESS;AttachDbFilename=I:\Samsung_service\TestSamsung\TestSamsung\Test.mdf;Integrated Security=True;User Instance=True"
Dim conn As New SqlConnection(constr)
Dim query As String
query = "select * from Customers"
Dim da As New SqlDataAdapter(query, conn)
Dim ds As Data.DataSet = New Data.DataSet("Customers")
da.Fill(ds, "Customers")
Dim table As New Data.DataTable
table = ds.Tables("Customers")
Dim newrow As Data.DataRow
newrow = table.NewRow()
newrow("bill_no") = TextBox1.Text
newrow("cust_name") = TextBox2.Text
newrow("addr") = TextBox3.Text
'newrow("telephone1") = TextBox4.Text
'newrow("t2") = TextBox5.Text
newrow("t3") = TextBox6.Text
newrow("model_name") = TextBox7.Text
newrow("serial_no_SN") = TextBox8.Text
newrow("s2_ESN") = TextBox9.Text
newrow("s3_IMEI") = TextBox10.Text
newrow("pur_date") = DateTimePicker1.Text
newrow("defect_descrpn") = TextBox11.Text
newrow("accessory") = TextBox12.Text
newrow("remark") = TextBox13.Text
Dim builder As New SqlCommandBuilder(da)
da.InsertCommand = builder.GetInsertCommand()
da.Update(ds, "Customers")
da.Fill(ds, "Customers")
table = ds.Tables("Customers")
MsgBox("Data Has Been Saved Successfully....")
Catch ex As Exception
' MsgBox(ex.Message)
MsgBox("Check Details Entered. ")
End Try
End If
If TextBox6.Text = "" Then
ErrorProvider6.SetError(TextBox6, "Compulsoy Field")
End If

End Sub

second problem is have a print form in a particular format but the data retrieval in textboxes is not happening actally i dont know what to do.
haven't written any code yet
what whould e the code for data retrieval from database into their respective textboxes?

Recommended Answers

All 4 Replies

Sorry, is that code meant to simply insert the data the user entered in the text boxes into the database?

For the second part of your question you need to use SQL to run a SELECT statement on the database, pulling out the record of one customer I assume, and storing that in another dataTable. There you can access the cols of the dataTable to put data in the textboxs.
TextBox1.Text = dataTable.Rows[0][0].ToString()
TextBox2.Text = dataTable.Rows[0][1].ToString()... etc

yes it is

and for the second part i am using dataset fields directly and insrting them is it ok?

DataSets are fine, they are just a container for dataTables so the technique is the same.

It seems a bit wasteful to select all of the customers and hold them in a dataTable just to insert a new row. You could always just do an SQL insert command right at the start.

When you say you have to restart the application is it crashing with an error, just turning off or do you need to restart it to make it start processing again (it doesn't turn off but seems to stop working).

yup i want to insert multiple entries at a time and that entries must be shown in other form also without restarting the application...

also want to print in a4 size format it prints also but image is BLUR wht to do?

the code i am using for print is : -

Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage

Dim myImage As New Bitmap(Me.Width, Me.Height)
Dim PrintSize As Size = e.MarginBounds.Size
Dim scale As Double = 1

Me.DrawToBitmap(myImage, New Rectangle(Point.Empty, Me.Size))

PrintSize.Width *= 0.96 'convert to pixels
PrintSize.Height *= 0.96

If myImage.Width > PrintSize.Width Then
'Form is to big. Scale it down.
scale = PrintSize.Width / myImage.Width
e.Graphics.ScaleTransform(scale, scale)
End If

If (myImage.Height * scale) > PrintSize.Height Then
'The form is still to big. Scale it again.
scale = PrintSize.Height / (myImage.Height * scale)
e.Graphics.ScaleTransform(scale, scale)
End If

e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
e.Graphics.DrawImage(myImage, e.MarginBounds.Location)


End Sub

Private Sub Form1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown

If e.KeyCode = Keys.P AndAlso (e.Control AndAlso e.Alt) Then
If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
End If
End If

End Sub

Private Sub CustomersBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustomersBindingNavigatorSaveItem.Click

End Sub

Private Sub Ser_cen_prtfrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'CustomersTestDataSet.Customers' table. You can move, or remove it, as needed.

End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.