I have converted my project from VB.net to C# using converter sw
Now i m facing some errors , which i try to remove
Here is the code in c# and vb.net also
But main thing is that it does not give error in vb.net
error is ,Error:- Use of unassingned local varialble "tmpYear"
public void cmdSearch_Click(System.Object sender, System.EventArgs e)
{
try
{
frmStudentSearch dlgStudentSearch = new frmStudentSearch();
int iStudentID;
string strCboSelection;
DataTable tmpDataTable;
string strSQL;
DataTable tmpYear;
DataTable tmpData;
DataTable tmpCboDataTable;
dlgStudentSearch.ShowForm();
//MsgBox("Student Fees" + vbCrLf + "iStudentID :: " + _CConstant._iStudentID.ToString)
iStudentID = modMain._CConstant._iStudentID;
if (iStudentID > 0)
{
strCboSelection = "SELECT ID, Name FROM tblStudent";
tmpCboDataTable = modMain._CDatabase.GetDataTable(strCboSelection);
CboStudentName.SelectedValue = iStudentID.ToString();
if (CboStudentName.Text.Trim().Length != 0)
{
strSQL = "SELECT BatchID FROM tblStudent ";
strSQL += "WHERE ID = " + CboStudentName.SelectedValue.ToString() + " ";
tmpYear = modMain._CDatabase.GetDataTable(strSQL);
if (tmpYear.Rows.Count > 0)
{
if (Information.IsDBNull(tmpYear.Rows[0]["BatchID"]) == true)
{
Interaction.MsgBox("Batch Not Present For This Student", MsgBoxStyle.Information, null);
cmdSave.Enabled = false;
return;
}
else
{
cmdSave.Enabled = true;
}
}
}
strSQL = "SELECT ClassID,SectionID FROM tblStudentDetail ";
strSQL += "WHERE StudentID = " + CboStudentName.SelectedValue.ToString() + " ";
strSQL += "AND OrganizationID = " + modMain._CVariable._ORGANIZATIONID.ToString() + " ";
tmpDataTable = modMain._CDatabase.GetDataTable(strSQL);
if (tmpDataTable.Rows.Count == 0)
{
Interaction.MsgBox("No Student Details Present For This Student", MsgBoxStyle.Information, null);
cmdSave.Enabled = false;
return;
}
else
{
cmdSave.Enabled = true;
}
if (cmdSave.Enabled == true)
{
strSQL = "SELECT Amount FROM tblLibraryStaticFees ";
strSQL += "WHERE BatchID = " + tmpYear.Rows[0]["BatchID"].ToString() + " ";
//In the above line of code it says that ,Error:- Use of unassingned local varialble "tmpYear"
strSQL += "AND ClassID = " + tmpDataTable.Rows[0]["ClassID"].ToString() + " ";
strSQL += "AND SectionID = " + tmpDataTable.Rows[0]["SectionID"].ToString() + " ";
strSQL += "AND OrganizationID = " + modMain._CVariable._ORGANIZATIONID.ToString() + " ";
tmpData = modMain._CDatabase.GetDataTable(strSQL);
if (tmpData.Rows.Count > 0)
{
txtRegAmount.Text = (string) (tmpData.Rows[0]["Amount"]);
}
else
{
txtRegAmount.Text = "0";
}
}
}
}
catch (Exception ex)
{
LibraryManagement.CError.ShowError(ex, true, false.ToString(), "");
}
}
Code in VB.net in which no error
Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
Try
Dim dlgStudentSearch As New frmStudentSearch
Dim iStudentID As Int32
Dim strCboSelection As String
Dim tmpDataTable As DataTable
Dim strSQL As String
Dim tmpYear As DataTable
Dim tmpData As DataTable
Dim tmpCboDataTable As DataTable
dlgStudentSearch.ShowForm()
'MsgBox("Student Fees" + vbCrLf + "iStudentID :: " + _CConstant._iStudentID.ToString)
iStudentID = _CConstant._iStudentID
If iStudentID > 0 Then
strCboSelection = "SELECT ID, Name FROM tblStudent"
tmpCboDataTable = _CDatabase.GetDataTable(strCboSelection)
CboStudentName.SelectedValue = iStudentID.ToString
If Len(Trim(CboStudentName.Text)) <> 0 Then
strSQL = "SELECT BatchID FROM tblStudent "
strSQL += "WHERE ID = " + CboStudentName.SelectedValue.ToString + " "
tmpYear = _CDatabase.GetDataTable(strSQL)
If tmpYear.Rows.Count > 0 Then
If IsDBNull(tmpYear.Rows(0).Item("BatchID")) = True Then
MsgBox("Batch Not Present For This Student", MsgBoxStyle.Information)
cmdSave.Enabled = False
Exit Sub
Else
cmdSave.Enabled = True
End If
End If
End If
strSQL = "SELECT ClassID,SectionID FROM tblStudentDetail "
strSQL += "WHERE StudentID = " + CboStudentName.SelectedValue.ToString + " "
strSQL += "AND OrganizationID = " + _CVariable._ORGANIZATIONID.ToString + " "
tmpDataTable = _CDatabase.GetDataTable(strSQL)
If tmpDataTable.Rows.Count = 0 Then
MsgBox("No Student Details Present For This Student", MsgBoxStyle.Information)
cmdSave.Enabled = False
Exit Sub
Else
cmdSave.Enabled = True
End If
If cmdSave.Enabled = True Then
strSQL = "SELECT Amount FROM tblLibraryStaticFees "
strSQL += "WHERE BatchID = " + tmpYear.Rows(0).Item("BatchID").ToString + " "
strSQL += "AND ClassID = " + tmpDataTable.Rows(0).Item("ClassID").ToString + " "
strSQL += "AND SectionID = " + tmpDataTable.Rows(0).Item("SectionID").ToString + " "
strSQL += "AND OrganizationID = " + _CVariable._ORGANIZATIONID.ToString + " "
tmpData = _CDatabase.GetDataTable(strSQL)
If tmpData.Rows.Count > 0 Then
txtRegAmount.Text = tmpData.Rows(0).Item("Amount")
Else
txtRegAmount.Text = 0
End If
End If
End If
Catch ex As Exception
CError.ShowError(ex, True, False)
End Try
End Sub
So what is doing wrong in c# code?
Loading

Suthish NairPosted Oct 1, 2010, 3:59 AM
Rebuid your website, check the Error List + Warnings tab.. you will get the list of all unassigned variables. These types of issues occurs when you migrate old ones to new versions. Old versions of VS did not helped us to find this types of warnings or errors. Thanks to advanced VS versions.
The better you know your coding, the better your application performance.
about int object, it has a default value of zero (0) -
for more reading refer msdn: http://msdn.microsoft.com/en-us/library/83fhsxwc(vs.71).aspx
yes i agree with Sam..
Also there is good article by Jaish Mathews, readon:
http://www.c-sharpcorner.com/UploadFile/jaishmathews/WorkingofReferenceTypeandValueType09102006022502AM/WorkingofReferenceTypeandValueType.aspx
Sam HobbsPosted Oct 1, 2010, 3:36 AM
Vikas AhlawatPosted Oct 1, 2010, 3:25 AM
My this problem is solved by using
Sam HobbsPosted Oct 1, 2010, 3:15 AM
Correct?
Gomathi Palaniswamy: Why not explain what the problem is of you think it is different from that?
Vikas AhlawatPosted Oct 1, 2010, 3:08 AM
you r right
But what can i do with
int iStudentid;
Gomathi PalaniswamyPosted Oct 1, 2010, 2:57 AM
The data table can be initiated with out any value.I think that will not be the error here.
Sam HobbsPosted Oct 1, 2010, 2:54 AM
Suthish NairPosted Oct 1, 2010, 2:42 AM