【发布时间】:2014-02-23 11:18:30
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Text.RegularExpressions;
namespace WareHouseManagementSystems
{
class connection
{
public SqlConnection con = new SqlConnection();
public SqlCommand com = new SqlCommand();
public SqlDataReader dr;
public void connect()
{
try
{
con.ConnectionString ="Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\WAREHOUSEMANAGEMENTSYSTEMS_VS2008\\WAREHOUSEMANAGE MENTSYSTEMS_VS2008\\DATABASE\\2008\\WAREHOUSEMANAGEMENT.MDF;Integrated Security=True;Connect Timeout=30;User Instance=True";
con.Open();
com.Connection = con;
com.CommandType = CommandType.Text;
}
catch
{
}
}
public bool isValidEmail(string inputEmail)
{
string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
Regex re = new Regex(strRegex);
if (re.IsMatch(inputEmail))
return (true);
else
return (false);
}
}
}
每当我调试它时,我都会收到一条错误消息
executereader:连接属性未初始化
我尝试检查连接路径,所有内容都更改为所需的路径或位置。但一切都是徒劳的。
【问题讨论】:
-
你的代码真的是这样格式化的吗?我没想到会这样。请格式化您帖子中的代码,以便于阅读。另外,你真的有一个空的 catch 块吗?这意味着您在打开连接时看不到任何错误 - 这很可能是问题所在......
-
查看调用 ExecuteReader 的代码也很有用。
-
另外,摆脱那个 try/catch 块。将代码保留在 try 中,但摆脱块 - 您忽略了异常。
标签: c# database visual-studio-2010 connection desktop-application