I have a table with records, I need to read all the records of certain fields and if those fields are empty assign a variable to the value zero and if it contains some value assign the result to a variable. I have the code in VB but I need the code in c# with sql db
CODE IN VB
Public Sub formT1() Dim SQL As String Dim base As Database Set base = CurrentDb Dim rst As Recordset Dim code_em As String Set rst = base.OpenRecordset("SELECT * FROM [MEmp] WHERE [MEmp].[] = 2011") Do While rst.EOF = False If IsNull(rst.Fields("CODE")) Then code_em = "0" Else code_em = rst.Fields("CODE") End If Call Regla_118(code_em) SQL = "INSERT INTO VALIDATE(REGLA_118) VALUES" _& "('" & Regla118 & "')" DoCmd.RunSQL SQL rst.MoveNext Loop base.Close Set base = Nothing End Sub
CODE I have tried in C#
public static void ValidarT1(string C_E) { string constr = ConfigurationManager.ConnectionStrings["Constring"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { string query = "SELECT * FROM Empresas_Relacionadas"; using (SqlCommand cmd = new SqlCommand(query)) { cmd.Connection = con; con.Open(); using (SqlDataReader sdr = cmd.ExecuteReader()) { while (sdr.Read()) { if (sdr.get) { C_E = "0"; } else { //C_E = Value column } ReglaController.Regla_1(C_E); // INSERT TO Table } } con.Close(); } } }