|
In C#2.0,the Codedom library how to generate the method of foreach?
|
|
|
|
|
A foreach is actually a convenience wrapper around a loop with an enumerator. That's what you need to enumerate over. Try to create a CodeDOM for this instead:
IEnumerator e = item.GetEnumerator();
while(e.MoveNext())
{
myList.Add(ConvertToObject(item));
}
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi,
I have an application in C# that use SQL Server 2008 R2 Express.
When i install the package i need to choose option and to install:
1. Microsoft .Net Framework 3.5 SP1.
2. Windows Installer 4.5.
3. Windows PowerShell 1.0
I have an SQL Script that will build my DB at SQL 2008 R2 Express and will add the user configuration that i want.
I want to make install package that will include the SQL 2008 R2 Express (including "Microsoft .Net Framework 3.5 SP1.",
,"Windows Installer 4.5" and "Windows PowerShell 1.0 ").
Will run the script and install my application.
I don't want to let the user to choose configuration for the DB in the installation process.
How can i do that?
Thanks,
Shai.
|
|
|
|
|
|
Guys;
I used system.drawing.Image to get a MetaFile, the type is an EMF file:
Image img= new Metafile(new System.IO.MemoryStream(), HDC,rc, MetafileFrameUnit.Pixel, EmfType.EmfOnly);
After an EMF file is created. I need to convert it to Bitmap, using: img.Save(sTempfilename, ImageFormat.bmp); Its background becomes black. I think i can not save directly since the format is different.
Would you give some suggestions on how to convert the EMF image to a Bitmap? Thanks very much.
|
|
|
|
|
|
Thanks a lot!
|
|
|
|
|
My Pleasure.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Do you want to develop Rich Internet Applications for the enterprise? Do you want to know how Flex integrates with enterprise services using LiveCycle DS/BlazeDS? Anne Kathrine Petteroe will be in Bangalore this August to explain how you can use Adobe's Flash Platform to develop Rich Internet Applications for the enterprise. It will starts with discussing the typical challenges of enterprise application development and why choosing the right UI strategy is important. This part also covers architectural considerations. Next, see how Flex integrates with enterprise services using LiveCycle DS/BlazeDS or Web Services. At Adobe Flash Platform Summit 2010, to be held 25-26 August, Anne will also give examples and experiences from integrating with SAP back-end.
Anne Kathrine Petteroe is an Enterprise Platform Evangelist at Adobe. Before joining Adobe she was a SAP consultant with focus on UI development and strategy, as well as RIAs, Flex and form design. She is also the co-lead of ESME, an open source micromessaging platform for the enterprise.
Attend AFPS 2010 for the sheer value of the content! No other conference in India offers such a comprehensive mix of technical and creative content, delivered by the industry's leading speakers and platform experts. Across two days, you have access to over forty presentations including inspiring keynotes from legendary Adobe speakers. You also have the opportunity to hang out at the expo area and connect with Adobe partners, industry leaders and peer developers and designers. With over 2000 attendees sharing the same passion as you, imagine the opportunities to network and further your goals.
Need more reasons? As the single, largest Flash Platform conference in India, at AFPS you get to hear about stuff in the roadmap and future directions before anyone else. Some of the specific highlights include: deep dive sessions around the latest product releases in the Adobe Flash Platform including exciting recent developments like Flash on devices, and targeted sessions for newcomers to the platform as well. For more information, visit: www.adobesummit.com
AFPS 2010 is homespun by Saltmarch Media, producers of Great Indian Developer Summit and Developer March – India’s biggest and independent polyglot conference and portal for software developers.
A Saltmarch Media
E: info@saltmarch.com
Ph: +91 80 4005 1000
|
|
|
|
|
shankarjain2010 wrote: As the single, largest Flash Platform conference in India
You really are a grade A, full blown, moron of the highest order. First of all, this is advertising, so you shouldn't be posting it in the forums - secondly, and this proves you are a wlueless canker, what has this got to do with .NET?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
hi dude,
Please read this[^] guideline before you post anything in the thread.
Please do not market your product, Website or yourself in discussion forum. There are other sites which
allows you to do that, this is question answer forum.
You can tell some marketing company they will market your product or site. Like if you can tell google
then google will market according to your way but you need to pay for that.
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
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
|
|
|
|
|