|
I am using a stored procedure to insert data into two tables in sql 2008 server. Now while handling exception I am using exception code to check the exception and accordingly i am showing the error message to the user.Can u tell me a better option to do the same.
Public Sub rtrnQry(ByVal usrNm As String, ByVal psWd As String, ByVal fNm As String, _
ByVal lNm As String, ByVal empId As Integer, ByVal proNm As String, ByVal aDm As String, ByVal rowno As Integer)
Try
Using cn As New SqlConnection(sqlConnStr)
cn.Open()
Using cmd As New SqlCommand("InsrtLogin", cn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@empid", empId)
.Parameters.AddWithValue("@username", usrNm)
.Parameters.AddWithValue("@password", psWd)
.Parameters.AddWithValue("@firstname", fNm)
.Parameters.AddWithValue("@lastname", lNm)
.Parameters.AddWithValue("@adminpri", aDm)
.Parameters.AddWithValue("@proName", proNm)
.ExecuteNonQuery()
End With
End Using
End Using
Catch ex As SqlException
If chkBox1_Crtusr.Checked Then
If ex.Number.Equals(2627) Then 'Exception code for Primary Key Violation
MsgBox("Duplicate Employee ID cannot be inserted. Violation of Primary Key " & _
"Constraint Occured. Enter an unique value.Please check row number : 1", MsgBoxStyle.Critical, "Error")
Else
MsgBox(ex.ToString)
End If
If ex.Number.Equals(208) Then
MsgBox("Invalid Table Name. Check the Sql String.", MsgBoxStyle.Critical, "Error")
End If
End If
If chkBox2_Crtusr.Checked Then
If ex.Number.Equals(2627) Then 'Exception code for Primary Key Violation
MsgBox("Duplicate Employee ID cannot be inserted. Violation of Primary Key " & _
"Constraint Occured. Enter an unique value.Please check row number : 2", MsgBoxStyle.Critical, "Error")
Else
MsgBox(ex.ToString)
End If
If ex.Number.Equals(208) Then
MsgBox("Invalid Table Name. Check the Sql String.", MsgBoxStyle.Critical, "Error")
End If
Now I am calling the above procedure
Private Sub btnSubmit_CrtMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit_CrtMul.Click
Dim cnt As Integer = 0
Try
If chkBox1_Crtusr.Checked Then
rtrnQry(txtUsrNm_1.Text, txtPswd_1.Text, txtFName_1.Text, txtLName_1.Text, txtEmpID_1.Text, cmbProNm1.SelectedItem, cmbAdmin1.SelectedItem, 1)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_1.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
Call ClearData(1)
cnt = cnt + 1
End If
End If
If chkBox2_Crtusr.Checked Then
rtrnQry(txtUsrNm_2.Text, txtPswd_2.Text, txtFName_2.Text, txtLName_2.Text, txtEmpID_2.Text, cmbProNm2.SelectedItem, cmbAdmin2.SelectedItem, 2)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_2.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
Call ClearData(2)
cnt = cnt + 1
End If
End If
If chkBox3_Crtusr.Checked Then
rtrnQry(txtUsrNm_3.Text, txtPswd_3.Text, txtFName_3.Text, txtLName_3.Text, txtEmpID_3.Text, cmbProNm3.SelectedItem, cmbAdmin3.SelectedItem, 3)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_3.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
Call ClearData(3)
cnt = cnt + 1
End If
End If
Now when I am doing this, for each exception the error message is appearing twice, I need to take care of that as well. Please Help, Thanks in advance
modified on Friday, July 23, 2010 8:57 AM
|
|
|
|
|
You've posted the same question elsewhere: don't do that.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair.
nils illegitimus carborundum
me, me, me
|
|
|
|
|
Your code is unreadable, didn't you notice?
Please use <PRE> tags.
|
|
|
|
|
|
Please do not repost the same question more than once. If you have further information then modify your original query.
It's time for a new signature.
|
|
|
|
|
Hi,
i am new to vb.net and i am trying to reset all the textbox and combobox in my application as soon as execute query statement gets executed. Actually i have used a series of rows and combox to enter data to the table, if check box one is checked then i am allowing to the enter the data, my form looks somwthing like an excel sheet. I am able to enter data - without any problem, but i am unable to reset the feilds. please some help.
|
|
|
|
|
Unfortunately, your question is not very clear.
I would recommend you use a collection like a Dictionary (key and value) to keep track of your object(s).
|
|
|
|
|
As already noted, it's not entirely clear what you're trying to do. Post a bit of your code and we might be able to help.
But in the meantime, if I'm reading your post correctly, you want to clear the contents of your controls after you use them. It sounds as if they are all text controls, in which case you can clear them by iterating through all of them and setting the .Text property to "". That seems a bit inefficient to me, and probably unnecessary, but without seeing your code it's hard to say. If all you want to do is set up the controls for the next entry, you can use the Selected property on entering the field to let the user type a new value that replaces the old.
"A Journey of a Thousand Rest Stops Begins with a Single Movement"
|
|
|
|
|
As said your question is not very crear still I think you want to get the all controls in a specific form. If so you can use
Dim fControls As Control
Dim txtCur AS TextBox
For Each fControls In fCur.Controls
If fControls.GetType Is GetType(TextBox) Then
txtCur = CType(fControls, TextBox)
'Now do whatever you wants with the text box
end if
Next
This code will get you all the textboxes in a container named "fCur "
|
|
|
|
|
Hi ,
as i have already informed, i am trying to insert multiple user details to two different tables using a stored procedure from one form, after the successful execution of the query i want to clear the controls.
Please see code to get is clarified
Private Sub btnSubmit_CrtMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit_CrtMul.Click
Dim cnt As Integer = 0
Try
If chkBox1_Crtusr.Checked Then
rtrnQry(txtUsrNm_1.Text, txtPswd_1.Text, txtFName_1.Text, txtLName_1.Text, txtEmpID_1.Text, cmbProNm1.SelectedItem, cmbAdmin1.SelectedItem, 1)
' After the statement gets executed i want to clear all the controls using array control list or by any ' other option
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_1.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
chkBox1_Crtusr.CheckState = CheckState.Unchecked
txtUsrNm_1.Text = ""
txtPswd_1.Text = ""
txtFName_1.Text = ""
txtLName_1.Text = ""
txtEmpID_1.Text = ""
cmbProNm1.SelectedIndex = -1 ' project name
cmbAdmin1.SelectedIndex = -1 ' Admin privilege (boolean value)
cnt = cnt + 1
End If
End If
If chkBox2_Crtusr.Checked Then
rtrnQry(txtUsrNm_2.Text, txtPswd_2.Text, txtFName_2.Text, txtLName_2.Text, txtEmpID_2.Text, cmbProNm2.SelectedItem, cmbAdmin2.SelectedItem, 2)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_2.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
chkBox2_Crtusr.CheckState = CheckState.Unchecked
txtUsrNm_2.Text = ""
txtPswd_2.Text = ""
txtFName_2.Text = ""
txtLName_2.Text = ""
txtEmpID_2.Text = ""
cmbProNm2.SelectedIndex = -1
cmbAdmin2.SelectedIndex = -1
cnt = cnt + 1
End If
End If
If chkBox3_Crtusr.Checked Then
rtrnQry(txtUsrNm_3.Text, txtPswd_3.Text, txtFName_3.Text, txtLName_3.Text, txtEmpID_3.Text, cmbProNm3.SelectedItem, cmbAdmin3.SelectedItem, 3)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_3.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
chkBox3_Crtusr.CheckState = CheckState.Unchecked
txtUsrNm_3.Text = ""
txtPswd_3.Text = ""
txtFName_3.Text = ""
txtLName_3.Text = ""
txtEmpID_3.Text = ""
cmbProNm3.SelectedIndex = -1
cmbAdmin3.SelectedIndex = -1
cnt = cnt + 1
End If
End If
If chkBox4_Crtusr.Checked Then
rtrnQry(txtUsrNm_4.Text, txtPswd_4.Text, txtFName_4.Text, txtLName_4.Text, txtEmpID_4.Text, cmbProNm4.SelectedItem, cmbAdmin4.SelectedItem, 4)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_4.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
chkBox4_Crtusr.CheckState = CheckState.Unchecked
txtUsrNm_4.Text = ""
txtPswd_4.Text = ""
txtFName_4.Text = ""
txtLName_4.Text = ""
txtEmpID_4.Text = ""
cmbProNm4.SelectedIndex = -1
cmbAdmin4.SelectedIndex = -1
cnt = cnt + 1
End If
End If
If chkBox5_Crtusr.Checked Then
rtrnQry(txtUsrNm_5.Text, txtPswd_5.Text, txtFName_5.Text, txtLName_5.Text, txtEmpID_5.Text, cmbProNm5.SelectedItem, cmbAdmin5.SelectedItem, 5)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_5.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
chkBox5_Crtusr.CheckState = CheckState.Unchecked
txtUsrNm_5.Text = ""
txtPswd_5.Text = ""
txtFName_5.Text = ""
txtLName_5.Text = ""
txtEmpID_5.Text = ""
cmbProNm5.SelectedIndex = -1
cmbAdmin5.SelectedIndex = -1
cnt = cnt + 1
End If
End If
Catch ex As SqlException
MsgBox(ex.ToString)
End Try
MsgBox("Number of user inserted successfully is : " & cnt, MsgBoxStyle.Information, "Multi User Insert Information")
End Sub
Public Sub rtrnQry(ByVal usrNm As String, ByVal psWd As String, ByVal fNm As String, _
ByVal lNm As String, ByVal empId As Integer, ByVal proNm As String, ByVal aDm As String, ByVal rowno As Integer)
Try
Using cn As New SqlConnection(sqlConnStr)
cn.Open()
Using cmd As New SqlCommand("InsrtLogin", cn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@empid", empId)
.Parameters.AddWithValue("@username", usrNm)
.Parameters.AddWithValue("@password", psWd)
.Parameters.AddWithValue("@firstname", fNm)
.Parameters.AddWithValue("@lastname", lNm)
.Parameters.AddWithValue("@adminpri", aDm)
.Parameters.AddWithValue("@proName", proNm)
.ExecuteNonQuery()
End With
End Using
End Using
Catch ex As SqlException
msgbox(ex.tostring)
End Try
End Sub
|
|
|
|
|
See my previous post. Change the fCur. to Me. and use txtCur.Text = "" after txtCur = CType(fControls, TextBox) statement and paste it where you want to clear all values.
|
|
|
|
|
i understand but then i want to clear txtUsrNm_1.Text = "",txtPswd_1.Text ,txtFName_1.Text ,txtLName_1.Text ,txtEmpID_1.Text ,cmbProNm1.SelectedIndex ,cmbAdmin1.SelectedIndex when chkBox1_Crtusr.CheckState = CheckState.Unchecked, again for chkBox2_Crtusr.CheckState = CheckState.Unchecked i want to clear txtUsrNm_2.Text = "",txtPswd_2.Text = "",txtFName_2.Text = "",txtLName_2.Text = "",txtEmpID_2.Text = ""
,cmbProNm2.SelectedIndex = -1,cmbAdmin2.SelectedIndex = -1,
I believe you code will clear all the controls in the form, actually my form looks like an excel sheet, for every checked box checked i want to clear the corresponding row.
|
|
|
|
|
Well then you need some logic to do your job.
May be you can use the Tag property of a control to do your job.
Specify same tag for all set of controls you want clear.
Then clear all controls with the same Tag
Private Sub ClearData(nTag as string)
Dim fControls As Control
Dim txtCur AS TextBox
For Each fControls In Me.Controls
If fControls.GetType Is GetType(TextBox) Then
txtCur = CType(fControls, TextBox)
if txtCur.Tag = nTag then txtCur.Text = ""
end if
Next
End Sub
Or may be you can use a GroupBox to separate your Control Set and replace Me.Controls to GroupBox1.Controls
Now you need to use your own logic to do your job. Isnt it?
|
|
|
|
|
Hi Goutam,
your code worked, thanks a lot, thnx for teaching the tag property. I have one more question for you. I am using a stored procedure to insert data into two tables in sql 2008 server. Now while handling exception i am using exception code to check the exception and accordingly i am showing the error message to the user.Can u tell me a better option to do the same.
==================================================================
Public Sub rtrnQry(ByVal usrNm As String, ByVal psWd As String, ByVal fNm As String, _
ByVal lNm As String, ByVal empId As Integer, ByVal proNm As String, ByVal aDm As String, ByVal rowno As Integer)
Try
Using cn As New SqlConnection(sqlConnStr)
cn.Open()
Using cmd As New SqlCommand("InsrtLogin", cn)
With cmd
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@empid", empId)
.Parameters.AddWithValue("@username", usrNm)
.Parameters.AddWithValue("@password", psWd)
.Parameters.AddWithValue("@firstname", fNm)
.Parameters.AddWithValue("@lastname", lNm)
.Parameters.AddWithValue("@adminpri", aDm)
.Parameters.AddWithValue("@proName", proNm)
.ExecuteNonQuery()
End With
End Using
End Using
Catch ex As SqlException
If chkBox1_Crtusr.Checked Then
If ex.Number.Equals(2627) Then 'Exception code for Primary Key Violation
MsgBox("Duplicate Employee ID cannot be inserted. Violation of Primary Key " & _
"Constraint Occured. Enter an unique value.Please check row number : 1", MsgBoxStyle.Critical, "Error")
Else
MsgBox(ex.ToString)
End If
If ex.Number.Equals(208) Then
MsgBox("Invalid Table Name. Check the Sql String.", MsgBoxStyle.Critical, "Error")
End If
End If
If chkBox2_Crtusr.Checked Then
If ex.Number.Equals(2627) Then 'Exception code for Primary Key Violation
MsgBox("Duplicate Employee ID cannot be inserted. Violation of Primary Key " & _
"Constraint Occured. Enter an unique value.Please check row number : 2", MsgBoxStyle.Critical, "Error")
Else
MsgBox(ex.ToString)
End If
If ex.Number.Equals(208) Then
MsgBox("Invalid Table Name. Check the Sql String.", MsgBoxStyle.Critical, "Error")
End If
================================Now i am calling the above proc ===========================
Private Sub btnSubmit_CrtMul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit_CrtMul.Click
Dim cnt As Integer = 0
Try
If chkBox1_Crtusr.Checked Then
rtrnQry(txtUsrNm_1.Text, txtPswd_1.Text, txtFName_1.Text, txtLName_1.Text, txtEmpID_1.Text, cmbProNm1.SelectedItem, cmbAdmin1.SelectedItem, 1)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_1.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
Call ClearData(1)
cnt = cnt + 1
End If
End If
If chkBox2_Crtusr.Checked Then
rtrnQry(txtUsrNm_2.Text, txtPswd_2.Text, txtFName_2.Text, txtLName_2.Text, txtEmpID_2.Text, cmbProNm2.SelectedItem, cmbAdmin2.SelectedItem, 2)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_2.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
Call ClearData(2)
cnt = cnt + 1
End If
End If
If chkBox3_Crtusr.Checked Then
rtrnQry(txtUsrNm_3.Text, txtPswd_3.Text, txtFName_3.Text, txtLName_3.Text, txtEmpID_3.Text, cmbProNm3.SelectedItem, cmbAdmin3.SelectedItem, 3)
Dim sqlLogin As String = "Select * from login where user_name ='" & txtUsrNm_3.Text & "'"
Dim usrVerified As String = DataStore.ExecuteScalar(sqlLogin, sqlConnStr)
If usrVerified.Length > 0 Then
Call ClearData(3)
cnt = cnt + 1
End If
End If
================================================================================================
Now when i am doing this, for each exception the error message is appearing twice, i need to take care of that as well. Please Help, Thanks in advance
|
|
|
|
|
|
Hello. I've got a bit of a strange error and I can't seem to find much information about ways to fix it.
I have a ClickOnce deployed application that is accessed by multiple clients, all with various Windows operating systems. It seems this error only occurs for those with Windows XP, but not for all Windows XP users.
I have a timer that kicks off every 10 minutes that makes a call to ApplicationDeployment.CurrentDeployment.CheckForUpdate(). Within this call, I get the exception --
Error: System.Deployment.Application.InvalidDeploymentException: Exception reading manifest from http://server/AppName.Client.application: the manifest may not be valid or the file could not be opened. ---> System.Deployment.Application.InvalidDeploymentException: Deployment manifest is not semantically valid. ---> System.Deployment.Application.InvalidDeploymentException: The name of the application reference identity as invalid characters: AppName.Client.exe.
at System.Deployment.Application.Manifest.AssemblyManifest.ValidateApplicationDependency(DependencyAssembly da)
at System.Deployment.Application.Manifest.AssemblyManifest.ValidateSemanticsForDeploymentRole()
--- End of inner exception stack trace ---
at System.Deployment.Application.Manifest.AssemblyManifest.ValidateSemanticsForDeploymentRole()
at System.Deployment.Application.Manifest.AssemblyManifest.ValidateSemantics(ManifestType manifestType)
at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
--- End of inner exception stack trace ---
at System.Deployment.Application.ManifestReader.FromDocument(String localPath, ManifestType manifestType, Uri sourceUri)
at System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirect(SubscriptionStore subStore, Uri sourceUri, TempFile tempFile, IDownloadNotification notification, DownloadOptions options, ServerInformation serverInformation)
at System.Deployment.Application.DownloadManager.DownloadDeploymentManifest(SubscriptionStore subStore, Uri sourceUri, TempFile tempFile, IDownloadNotification notification, DownloadOptions options)
at System.Deployment.Application.DeploymentManager.BindCore(Boolean blocking, TempFile tempDeploy, TempDirectory tempAppDir, FileStream refTransaction, String productName)
at System.Deployment.Application.DeploymentManager.Bind()
at System.Deployment.Application.ApplicationDeployment.CheckForDetailedUpdate()
at System.Deployment.Application.ApplicationDeployment.CheckForUpdate()
at AppName.Client.MainForm.WatchForDeployment() in D:\AppName\MainForm.cs
If anyone else is familiar with this exception and has some ideas about how to fix it, I'm all ears!!
Thanks!!
Mia
|
|
|
|
|
hi, try to following this steps.
Clean your solution.
Delete all files and folders from your drop site.
Rebuild all.
Republish.
On the client side, remove all previous versions of the deployment.
Then reinstall. This fixed it for my team.
Find more information on this[^] link.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Hi,
In my application, I have a gridview which is visible with a blank row on Page_Load. The GV has 4 columns of which the first column is an editable textbox. The rest 3 are bound fields. When I enter a valid ID in the textbox cell and hit the Enter key(TextChanged Event), the rest of the 3 fields are bound and a new empty row is created below this row. But my problem is , when I enter the second data and hit Enter, the first row is lost and is replaced with this second row( Datatable not holding values on Postback). Kindly help...!!!
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
if (ID valid and data returned)
{
Addnewemptyrow; //For next input
Bind data to current row;
}
if(Invalid ID and data not returned)
{
Cells[1].Text = ""; // Clear the current row values(Make it as a new row)
Cells[2].Text = "";
Cells[3].Text = "";
}
|
|
|
|
|
First, this should have been posted to the ASP.NET forum
During the postback the new values must be persisted to the datasource for your grid. Otherwise, when the grid is re-bound it course knows nothing about the new row.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
how to create web organisation chart using mysql database in C#, ASP.net. Anybody please help me.
|
|
|
|
|
What have you tried so far?
Some third party products provide these features[^].
|
|
|
|
|
I downloaded some organisation chart application in google but it is giving errors and i am not getting proper link. i am using mysql database. If u have any C#.net mysql database organisation chart application please formard me.
Please give any download links related to above if you know. thanks in advance.
modified on Friday, July 23, 2010 3:28 AM
|
|
|
|
|
HOw can i give answer of any question ,that is call by any person about my previous question
|
|
|
|
|
If you mean this question[^], you can use the "Add comment" selector beneath the answers to post a reply to the person who gave the answer.
It's time for a new signature.
|
|
|
|
|
Provide a link to your previous question.
|
|
|
|
|