阅读两列以获取价值 [英] reading two columns to get value

查看:82
本文介绍了阅读两列以获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi to al!

这是我通过传递两个列字段来使用存储过程的函数

并必须从sql server中检索一个值

我不知道我的错误在哪里


hi to al!

here is my function in which i used a store procedure by passing two column field

and have to retrieve one value from sql server

i dont know where is my mistake


public static void dispaly_functions_module_role(string proc_fun, int mod_int, int rol_int, CheckedListBox c1)
       
        {
            try
            {
                int count = 0;
                int count1 = 0;
                string sql_string = ("Data Source=dfgerttrt;Initial Catalog=sdrterter;User Id=fgrtrt;Password=rgdfgsdg");
                SqlConnection conn = new SqlConnection(sql_string);
                SqlCommand command = new SqlCommand(proc_fun, conn);
                conn.Open();
                command.CommandType = CommandType.StoredProcedure;
                command.Parameters.AddWithValue("@mid", mod_int);
                command.Parameters.AddWithValue("@rid", rol_int);
                SqlDataReader rdr = command.ExecuteReader();
                if (rdr.HasRows)
                {
                    StringBuilder sb = new StringBuilder();
                    string a;
                    while (rdr.Read())
                    {
                        sb.Append(((int)rdr[mod_int] && rdr[rol_int]));
                        sb.Append("\n");
                        a = sb.ToString().Trim();
                        c1.Items.Add(a);
                       // Items.Insert(count1, a);
                        sb.Length = 0;
                        count1++;
                    }
                }
                else
                {
                    if (count1 != 0)
                        MessageBox.Show(" your data is saved");
                    else
                        MessageBox.Show("not found");
                }
                rdr.Close();
                command.ExecuteNonQuery();
                count++;
                conn.Close();
                conn.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show("Error in database connection");
            }
        }

推荐答案

鉴于您想一次将StringBuilder扩展两个值,请尝试
Given that you want to extend your StringBuilder by two values at a time, try
sb.Append((int)rdr[mod_int]);
sb.Append((int)rdr[rol_int]);
sb.Append("\n");

,将它们紧接着放置在另一个位置一个换行符.

如果要用另一个换行符分隔它们,请插入另一个sb.Append("\n");.

根据您打算如何处理结果字符串,最好将"\n"也更改为Environment.NewLine.


对于您真正想要实现的目标,我可能完全错了.提议的&&运算符实际上用于对两个布尔值进行逻辑与,从而再次产生布尔值.但是在那种情况下,我不理解对int的强制转换.

That will put them directly after one another followed by one newline character.

If you want to separate them by another newline character, insert another sb.Append("\n");.

Depending on what you''re planning to do with the resulting string, it could be a good idea to change "\n" into Environment.NewLine as well.


I could be completely wrong on what you really want to achieve. Your proposed && operator is actually used to logically AND two boolean values, resulting again in a boolean. But in that case I don''t understand the cast to int.


这篇关于阅读两列以获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆